Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

      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.


In reply to Re: How to check if a website is up? by blue_cowdawg
in thread How to check if a website is up? by anev

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found