Computing.Net > Forums > Web Development > Code or Script to Email IP Address

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Code or Script to Email IP Address

Reply to Message Icon

Name: ronobvious
Date: January 12, 2009 at 13:11:38 Pacific
OS: OS X 10.4.11
CPU/Ram: Dual 2.5 GHz
Product: Apple / G5
Subcategory: Javascript/Ajax
Comment:

Hi, I'm somewhat new to the whole web design thing and was wondering if there was any way to put some code or a script into a web page that, when someone with the IP Address xx.xx.xx.xx hits that particular page, the code or script would automatically send an email at the time of the hit?

Is this possible? Can anyone post the code?

Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: January 14, 2009 at 11:24:39 Pacific
Reply:

With php, you could possibly try the mail function

<?php

   if(strcmp($_SERVER["REMOTE_ADDR"], "127.0.0.1") == 0) {
      $name = "sender's name";
      $from = "from@host";
      $sendto = "to@host";
      $body = "the page got a hit from:\r\n" . 
              $_SERVER["REMOTE_ADDR"] . "\r\n" .
              gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\r\n" .
              $_SERVER["HTTP_USER_AGENT"] . "\r\n" .
              date('M d, Y h:i a', time()) . "\r\n";
      $subject = "hit from target site";
      $header = "From: ". $name . " <" . $from . ">\r\n";
      mail($sendto, $subject, $body, $header);
   }
?>
rest of script

The second parameter in strcmp should be that of the ip you're looking for. I have no ideas on other scripting languages.

HTH


0

Response Number 2
Name: ronobvious
Date: January 19, 2009 at 12:06:07 Pacific
Reply:

It took me a while to figure out how to use php. I'm still quite foggy on it all, BUT the important thing is, after much trial and error trying to figure out how to apply your script, I did it! Thank you SOOOO much for your help in this. It was driving me crazy, and I finally figured out where to put what. Again, thank you for your help.


0

Response Number 3
Name: ronobvious
Date: January 19, 2009 at 13:22:17 Pacific
Reply:

I hate to ask for more, but I'm really excited that it's working. How would I input variables for more than one IP Address? For instance, I have it set to alert me when a specific IP address hits my page, but I'd also like to find out when an IP Address that starts out as (for instance) "32.143.xx.xx" hits my page. What are the variables or wildcards for the other digits in the IP Address that would allow me to do that?

Again, thank you so much for your help. I'm still learning (teaching myself through googling and trial and error) so please for give my thickness to what may be a very simple answer.


0

Response Number 4
Name: shutat
Date: January 22, 2009 at 14:04:52 Pacific
Reply:

<?php

   define("ADD1",  32);
   define("ADD2", 143);

   $ip = array("34.212.22.110", "32.212.100.143", "32.143.112.2", "65.23.111.233",
               "32.143.20.96", "113.32.143.11", "119.156.32.143");

   foreach($ip as $val) {   
      $pat = '/(' . ADD1 . '\.' . ADD2 . ')\.([[:alnum:]]+)\.([[:alnum:]]+)/';
      echo $val . (preg_match($pat, $val) > 0 ? " <strong>true</strong>" : " false") . "
";
   }

?>

I *think* something like above will work; I made an array to test ips, but you wouldn't need the foreach loop or the array.

replace

 if(strcmp($_SERVER["REMOTE_ADDR"], "127.0.0.1") == 0) {

with
 if(preg_match($pat, $_SERVER["REMOTE_ADDR"]) > 0) {
   // add mail routine here
}

I used define to "fix" part of the ip, but you can use variables too.

HTH


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


upload images from webpag... Microsoft Certificate Ser...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Code or Script to Email IP Address

Unable to determine IP address from www.computing.net/answers/webdevel/unable-to-determine-ip-address-from/2931.html

cant access webpage outside lan ..? www.computing.net/answers/webdevel/cant-access-webpage-outside-lan-/3045.html

How To Track people With IP Address www.computing.net/answers/webdevel/how-to-track-people-with-ip-address/2308.html