?
Solved

sending email upon computer logon

Posted on 2003-03-12
23
Medium Priority
?
263 Views
Last Modified: 2006-11-17
is there a way to detect when a computer comes online by detecting the ip address and then sending a notification to an email address(9535632@bellsouth.net.pe) saying that computer 192.168.0.101 (or whatever the pc's ip address is) has been turned on? when it is turned off

Thanks,
bartonjo2
0
Comment
Question by:bartonjo2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 6
  • 3
  • +2
23 Comments
 
LVL 15

Expert Comment

by:VGR
ID: 8123911
yes, of course, but only if the computer having that address goes to your server and encounters a PHP script ;-)

else build a windows/kylix application with a timer and a PING on the address
0
 
LVL 1

Expert Comment

by:beachbum_boy
ID: 8124213
This would be a pretty crazy way to do things but if you wanted to use PHP you could do the following:

1)Make a page that does a header refresh say every minute
2)The page then does a fsockopen on the ICMP (ping,echo request) port, OR does an exec("ping xxx.xxx.xxx.xxx");
3)Then based on the results of 2) sends an email using the mail(); command.

You would then have to open the page on a machine and leave it open OR else run the PHP as a cron job.

The above would probably work ok but it would be a pretty wacky use of PHP.
0
 
LVL 6

Expert Comment

by:carchitect
ID: 8125867
i hope do simple thing
in your site main page....like index.php
write this code on top of your file....

whenever anybody will open your site
mail will be sent....


$ip=getenv("REMOTE_ADDR");
mail('9535632@bellsouth.net.pe','new user','$ip has been turned on','From: youraddress@mail.com');
regards
0
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 
LVL 15

Expert Comment

by:VGR
ID: 8126081
carchitect, this will send a mail whenever someone refreshes that page 8-)

The solution of beachbum_boy is 100% correct, and it has happened that I did this 8-)
I prefer a Delphi app with timer to check the PING stuff, 'cause PHP is not meant for this, althought the (infamous ? :D ) trick of the refreshing IFRAME inside/hidden in a "normal" page is useful too.
0
 
LVL 6

Expert Comment

by:carchitect
ID: 8126175
hi you may session to prevent email sending again...
if session is active then don't send again
0
 
LVL 15

Expert Comment

by:VGR
ID: 8126204
exactly. But that's what I wrote above :D :D
"yes, of course, but only if the computer having that address goes to your server and encounters a PHP script ;-)"
0
 
LVL 6

Expert Comment

by:carchitect
ID: 8126255
all right
0
 
LVL 3

Author Comment

by:bartonjo2
ID: 8128358
VGR I am not skilled in vb and would not be able to port this program to a windows app,

beachbum_boy  could you show me some code that would do this
0
 
LVL 15

Expert Comment

by:VGR
ID: 8130944
how to ping a specified IP address and get teh max trip time in ms

Replace $sess_ip with your hardcoded IP@

<?
    // calcul vitesse ligne et mise à jour table utilisateurs (GetListeStatus reprend ces données)
    $lastline="";
    $lignes=array();
    $lastline=exec("ping -c2 -n -q $sess_ip",$lignes); // le mieux possible en non-root (-f)
    $tok = strtok ($lastline,"/");
    $tok = strtok ("/"); // saute le premier
    $tok = strtok ("/"); // saute le deuxième
    $tok = strtok ("/"); // saute le troisième
    //ne nous intéresse pas sauf si on était en -f (flood) : $moy=$tok;
    $tok = strtok ("/"); // au suivant
    $max=(double)substr($tok,0,strpos($tok,' ')); // on élimine " ms" de la chaîne
//debug
//echo "max $max<BR>";
//
?>
0
 
LVL 1

Expert Comment

by:Amerist
ID: 8139890
Build a php page that sends an email including all necessary info.

Put a batch file in the system's startup folder that calls the php page from the internet.

Then, whenever the computer starts up, the batch file will be called and the page will be accessed, sending the email.

Simple as that.
0
 
LVL 3

Author Comment

by:bartonjo2
ID: 8140349
hey amerist what if i need to know when my pc turns off though
0
 
LVL 15

Accepted Solution

by:
VGR earned 200 total points
ID: 8141740
one freidn of mine had the same problem. He wanted to overlook his DSL connection and retrieve the new IP@ after a line crash/recovery

The best solution is to implement a small program on the CLIENT (your PC) that sends out the IP@ periodically to some outside server, where you'll always be able to recover it.

Very easy, 30 lines of Delphi code and 10 lines of PHP are enough
0
 
LVL 1

Expert Comment

by:Amerist
ID: 8141867
Simple, just use this program:

http://users.pandora.be/jbosman/pwroff30.zip

It's free and has all source included
0
 
LVL 3

Author Comment

by:bartonjo2
ID: 8160620
VGR i am giving you the points but please show me how to use this suggestion :

one freidn of mine had the same problem. He wanted to overlook his DSL connection and retrieve the new IP@ after a line crash/recovery

The best solution is to implement a small program on the CLIENT (your PC) that sends out the IP@ periodically to some outside server, where you'll always be able to recover it.

Very easy, 30 lines of Delphi code and 10 lines of PHP are enough
0
 
LVL 3

Author Comment

by:bartonjo2
ID: 8160633
A (excellent) if you show me how to use your last comment
0
 
LVL 15

Expert Comment

by:VGR
ID: 8160914
ok, leave me some time
0
 
LVL 15

Expert Comment

by:VGR
ID: 8161499
ok, I offer you some solutions depending on what is running on the "monitored" machine :

-if it's a PC under Windows and it runs a webserver, I've a pretty good solution involving dynamic DNS (you'll have to pay for it, I dont provide this)

-if it's a PC under windows but you're not hosting anything, BUT you have a receiving machine able to host a simple PHP4 page, I can build a small program and the PHP page and it'll be nice : you'll see the current IP on the web page on the "receiving" server.

-if it's a PC under windows but you've only an email address to send the IP@ to, I also have a solution

which one do you want ?
0
 
LVL 3

Author Comment

by:bartonjo2
ID: 8161659
i have the last choice:
PC under windows i have an email address(bartonjo2@hotmail.com) to send the IP@ to
0
 
LVL 15

Expert Comment

by:VGR
ID: 8161980
ok, but for (2) any free hosting facility nowadays offers 100 MB free disk&web space, a MySql DB and PHP4 ;-))

I'll go now doing (3) for you.

No, don't thank me :D
0
 
LVL 15

Expert Comment

by:VGR
ID: 8161990
just tell me how you intend to receive the IP address ? On boot ? Then the program I'll send you will have to be in the start folder of windows. On a line crash/lease renewal ?  Both ?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8162435
anyway, I'm 99% done
0
 
LVL 15

Expert Comment

by:VGR
ID: 8162601
ok, done.

You can find the GetIPsend program (383KB) at http://www.edainworks.com , choose "third party tools" , switch to French for the yime being, and then it's at the top of section "developpement" ; check for "GetIPsend" (193KB ZIP)

The program will send the new IP@ at startup time (if in the Start folder of windows), and whenever the IP@ changes (polling time is configurable). The program minimizes itself to the SysTray. Usually I also provide more options like a "configure" form, an "help/about", but I simplified.

The program is able to use "email" and "uri" options from the command line.
To pass command line parameters, alter the "properties" of the Windows desktop link (LNK) to the program.
"email" option has this format :
email yourname@provider.com

and the received email is like this :
// IP address changed for host "athlon800"
// "athlon800"'s IP addresses are 169.254.217.36|213.193.168.186

(yes, you'll have all NICs IP@, the program can't decide which one is the "external" one ;-)

Note that in that mode you need a MAPI-enabled email client (like OE? or Eudora without security settings)

--------------
This is the result of the "uri" option :
your ( athlon800 ) host's last known external IP address is 213.193.168.186

(note that in this case only the "external world readable" IP@ is shown, of course.

That's displayed at the specified URI using that "receiver.php" file :
<?
if (substr($PATH_INFO,1)=='itsme') { // good, a request for update
  // let's take also the host name
  $host="( $par_host )";
  $ip=$REMOTE_ADDR;
  // now write in a database or a flat file and exit (no output)
  $fd=fopen("distantip.txt","w");
  fputs($fd,$host);
  fputs($fd,'&|&');
  fputs($fd,$ip);
  fclose($fd);
  exit;
} // request received (if not : simple surveillance)
// else display
header("Refresh: 5");
// read DB or flat file
$fd=@fopen("distantip.txt","r");
if ($fd) { // read
  $poubStr=trim(fgets($fd,1024));
  $zarbi=explode('&|&',$poubStr);
  $host=$zarbi[0];
  $ip=$zarbi[1];
  fclose($fd);
} else { // has not yet run
  $host='';
  $ip='still unknown';
}
echo "your $host host's last known external IP address is $ip<BR>";
?>

In this mode, the GetIPsend program is called with parameter line "uri www.yourdomain.org/receiver.php" (note that "http://" is not to be passed)

Note that the GetIPsend program isn't configured to handle proxies (I simplified it)

regards
0
 
LVL 3

Author Comment

by:bartonjo2
ID: 8163461
so in the properties the shortcut would be C:\WINDOWS\Desktop\GetIPsend.exe email bartonjo2@hotmail.com|192.168.0.101
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question