Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How to check if a website is up?

by blue_cowdawg (Monsignor)
on Apr 05, 2004 at 16:11 UTC ( [id://342657]=note: print w/replies, xml ) Need Help??


in reply to How to check if a website is up?

      So it will only tell me if the server is there, but won't let me know if I can access the content for that URL

Besides all of the suggestions where LWP::Simple are implemented you can also take a sniglet out of one of my scripts. This won't check the content itself but will check to see if the server in question is serving pages at all:

use Socket; : : # skip a few lines of a very large script : : sub portCheck { my ($host,$port)=@_; my ($iaddr,$paddr,$proto,$line); + $iaddr=inet_aton($host) or die "Could not aton!"; $paddr=sockaddr_in($port,$iaddr); $proto= getprotobyname('TCP'); socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; my $res=connect(SOCK, $paddr); + return 1 if $res; return 0; + + }
You would invoke it as in the following example:
: : : portCheck("www.mysite.com",80) or die "Server not serving!"; : :

If you want to check the content itself to make sure it hasn't been hacked or otherwise horribly modified then you might want to use LWP::Simple and friends runnng it one time when you know that A) the site is up and B) the page itelf is intact, generate an MD5 sum or some other fingerprint of your choosing and store that someplace for later comparison.

The sniglet above comes out of a very old script that I deployed a long time ago and it runs against several sites that I have interest in (clubs I belong to, my own web site, former customers of mine, etc.) and pages me if the site is unreachable so I can make the proper notifications.

I plan on overhauling it though given I have learned many better ways of doing things that the script does now which is why it hasn't been posted here in its entirety.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://342657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found