Josh Barton
asked on
sending email upon computer logon
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
Thanks,
bartonjo2
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.
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.
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.ne t.pe','new user','$ip has been turned on','From: youraddress@mail.com');
regards
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.ne
regards
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.
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.
hi you may session to prevent email sending again...
if session is active then don't send again
if session is active then don't send again
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 ;-)"
"yes, of course, but only if the computer having that address goes to your server and encounters a PHP script ;-)"
all right
ASKER
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
beachbum_boy could you show me some code that would do this
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($t ok,' ')); // on élimine " ms" de la chaîne
//debug
//echo "max $max<BR>";
//
?>
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
//debug
//echo "max $max<BR>";
//
?>
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.
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.
ASKER
hey amerist what if i need to know when my pc turns off though
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Simple, just use this program:
http://users.pandora.be/jbosman/pwroff30.zip
It's free and has all source included
http://users.pandora.be/jbosman/pwroff30.zip
It's free and has all source included
ASKER
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
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
ASKER
A (excellent) if you show me how to use your last comment
ok, leave me some time
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 ?
-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 ?
ASKER
i have the last choice:
PC under windows i have an email address(bartonjo2@hotmail. com) to send the IP@ to
PC under windows i have an email address(bartonjo2@hotmail.
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
I'll go now doing (3) for you.
No, don't thank me :D
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 ?
anyway, I'm 99% done
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)=='it sme') { // 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,10 24));
$zarbi=explode('&|&',$poub Str);
$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
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
(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)=='it
// 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",
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"
if ($fd) { // read
$poubStr=trim(fgets($fd,10
$zarbi=explode('&|&',$poub
$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
ASKER
so in the properties the shortcut would be C:\WINDOWS\Desktop\GetIPse nd.exe email bartonjo2@hotmail.com|192. 168.0.101
else build a windows/kylix application with a timer and a PING on the address