in reply to website availability ping

There is a module that may give you a little help on the ping command. Instead of doing a system call you could use NET::Ping. Here is an example:
#!/usr/bin/perl -w use strict; use Net::Ping; my $host = "XXX.XXX.XXX.XXX"; my $p = Net::Ping->new(); print "$host is alive.\n" if $p->ping($host); $p->close();
This module allows you to specify timeout values and also change the type (TCP,UDP, or ICMP) of echo requests that you send. (Up to 6 different protocols) Ex. you cannot ICMP www.micro$oft.com but you can establish a tcp request to the echo port and determine if the server is there. TCP seems to be a little better suited than ICMP but causes more overhead and traffic.

This module also allows you to do a service check (still not fool proof why HTTP or another service is not responding - that would require coding per service level). It has some return value checking to give you some reason why the response was negative.

I would use this first before trying to harvest an HTTP error on a remote server which may never reveal itself for various reasons.

Good Luck

Replies are listed 'Best First'.
Re: Re: website availability ping
by pg (Canon) on Oct 28, 2003 at 19:31 UTC

    ping does not fit in here at all. That a computer responses to ping, does not mean that the web site resides on it is alive. One the other hand, it is perfectly valid for a web site to be alive on a computer does not response to ping.

    They are just not related.

    Better go straight to deal with the issue by using LWP::UserAgent.

      I disagree. In his post he is trying to find problem determination by trying to retrieve a website. If by chance the http request is timing out (DOS, high traffic, etc) he will not receive an http error message besides "timed out". This just says that there was no reply to the request sent. If you read the original post I believe he is trying to get beyond the fact that the server is timing out.

      Continue to use LWP::UserAgent, but dig deeper to see what the problem is. Is the server up? (ICMP call) Is the port listening? (TCP call) Has ICMP been shut down? (Another TCP Call) All which can be accomplished through NET::Ping.

      The fact that an HTTP request times out does not mean that it is an HTTP problem.

      Understand that the word "Ping" as the original author used does not only apply to ICMP packets.

      The problem resolution is definately related.

        I purposely left this ping idea vague. I wanted to see what ideas would come my way. I may incorporate both Net::Ping and LWP:UserAgent in a rewrite that tells me more. Possibly, I could get response time statistics by using a low timeout, and increment until I wait long enough. After too much wait, I could use Net::Ping to see if the network is down. Then maybe something in the middle, like reporting the HTTP errors.

        Two problems. I will need to open the firewall some, or run ICMP as root. The firewall currently doesn't let the udp/tcp packets through the echo port 7.

        Second. I must have an older version of LWP, because there is no get method. I need to work on it again tomorrow.

        Thanks.