Click to See Complete Forum and Search --> : Dynamic IP Update Script - Ping Question


AndrewBeaton
12-12-2002, 11:06 AM
Hi All,

I have finally finished writing my perl script that updates a file on my webpage with my new IP address everytime it changes.

I run one on the client machine, that checks if the IP Address has changed upon Net connection and if so calls a cgi script on my webserver and passes it the relevent information.

This script then verifies the data and stored the details in a file. Calling the script normally will display the data.


What I am after tho is someway for a script on my webserver to "ping" the IP address it has and tell if it is online or not. Then it could display a message saying "online" / "offline" etc...

Can you use ping from an apache hosted site? if not do you have any recommendations on how I can do this?



With regards,

Andrew Beaton
linux@andrewbeaton.co.uk

tEd\newbie
12-12-2002, 03:43 PM
What you are looking for can be done with simple php code, try this:

<?php if(@fsockopen("<insert ip>", 80)) { print "online"; }

else { print "0ffline"; }

?>

The thing is, just crossed my mind now, if u use this snippet, then u will need something to update the IP data here to :P

AndrewBeaton
12-12-2002, 08:53 PM
Thanks for the reply.

I can give that a go, but im really planning on only using CGI.

I've done it all in sh script which worked but fancied trying some CGI... and everything works as it should just the server side.

I know now how to use ping from my webserver.. just gotta upload the program to my webspace and run it securely... but Im not sure how secure this will be...


Any other ideas .. but using CGI...


PS my plan is, when its all working to post it somewhere so that others can use it as well. Ive written it so that you only need to change a couple of variables to get it working on any version of linux and so far it works on FreeBSD and Redhat... so any non distro specific ideas would be better...




Cheers,

Andrew B

Stuka
12-13-2002, 02:50 PM
You could add perl code to your CGI that's updating the web page to do the same thing as the PHP snippet there. This bit use LWP::Simple;
if (head($url)) {
# ok document exists
print "Online";
}
else{
print "Offline";
}
is modified from lwpcook in the ActiveState perl docs, and SHOULD work, and be portable (as portable as Perl, at least), etc.

AndrewBeaton
12-15-2002, 04:01 PM
Thanx Stuka,

Ill give it a go....