Return-Path: Delivered-To: apmail-httpd-users-archive@httpd.apache.org Received: (qmail 85536 invoked by uid 500); 31 Oct 2002 17:10:17 -0000 Mailing-List: contact users-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: users@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list users@httpd.apache.org Received: (qmail 85522 invoked from network); 31 Oct 2002 17:10:16 -0000 Received: from email.archlab.tuwien.ac.at (128.131.118.17) by daedalus.apache.org with SMTP; 31 Oct 2002 17:10:16 -0000 Received: from cwirawan by email.archlab.tuwien.ac.at with local (Exim 3.35 #1 (Debian)) id 187Ili-0002MD-00 for ; Thu, 31 Oct 2002 18:06:06 +0100 Date: Thu, 31 Oct 2002 18:06:06 +0100 To: users@httpd.apache.org Message-ID: <20021031170606.GB20459@mail.archlab.tuwien.ac.at> References: <484A6CA492BE654395D208B1D8D5393973A486@SOMEXEVS001.ex.ordersx.org> <20021031121713.GA20459@mail.archlab.tuwien.ac.at> <3DC14FA1.9070004@ccidomain.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MW5yreqqjyrRcusr" Content-Disposition: inline In-Reply-To: <3DC14FA1.9070004@ccidomain.com> User-Agent: Mutt/1.4i From: Cahya Wirawan X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Subject: Re: [users@httpd] Testing if a Webserver is down --MW5yreqqjyrRcusr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Ok, I forget to check the unknown host, in your case it was succesfull connected and get http answer because if the host unknown, it connected to localhost and you have a webserver running on localhost :) also I just inserted one line to check the host. cahya. On Thu, Oct 31, 2002 at 10:43:29AM -0500, Kyle wrote: > Cahya, > > The program you attached always gives a "successful" reply even for > non-existent servers. :( > > I only wanted to run it once, so I changed the "while(1){" to "if(1){" > to make it run one time. I wanted to see the failure output, so he > server I chose to test was a fake one: www.asdfljja.com > > Here is what happens on one of my servers: > [dustdevil:/test root]# ./checkwebserver.pl > Thu Oct 31 10:16:48 2002: Testing www.asdfljja.com on port 80 ... > Thu Oct 31 10:16:48 2002: GET / answered. > Thu Oct 31 10:16:48 2002: Connected successfully. > > But there is no such server. > > BTW, I think this approach is great. It is a compromise between the > complexity of the wget/ultramonkey suggestions and the simplistic ping > options, which I think is a good fit for the majority of the Apache > sysadmins. If you correct the problem, I hope you will repost your > program to the group. > > -Kyle > --MW5yreqqjyrRcusr Content-Type: application/x-perl Content-Disposition: attachment; filename="checkwebserver.pl" Content-Transfer-Encoding: quoted-printable #!/usr/bin/perl=0A=0A$Host =3D "webserver.hostname.org";=0A$Port =3D 80;=0A= $Interval =3D 5; #in second=0A=0A$AF_INET =3D 2;=0A$SOCK_STREAM =3D 1;=0A$s= ockaddr =3D 'S n a4 x8';=0Achop($localHostname =3D `hostname`);=0A=0Awhile(= 1) {=0A testservice($Host,$Port);=0A sleep $Interval;=0A}=0A=0Asub testse= rvice {=0A local($testhost,$testport) =3D @_;=0A $now =3D localtime;=0A= =0A print STDERR "$now: Testing $testhost on port $testport ...\n";=0A =0A= ($name,$aliases,$proto) =3D getprotobyname('tcp');=0A ($name, $aliases, = $type, $len, $thisaddr) =3D gethostbyname($localHostname);=0A $this =3D pa= ck($sockaddr, $AF_INET, 0, $thisaddr);=0A=0A ($name,$aliases,$testport) = =3D getservbyname($testport,'tcp')=0A unless $testport =3D~ /^\d+$/;;=0A= ($name, $aliases, $type, $len, $thataddr) =3D gethostbyname($testhost);= =0A die "$now: $testhost is unknown host!\n" unless $thataddr;=0A $that = =3D pack($sockaddr, $AF_INET, $testport, $thataddr);=0A=0A # Create a hand= le to the socket=0A if (!socket(S, $AF_INET, $SOCK_STREAM, $proto)) {=0A = $reason =3D $!;=0A print STDERR "$now: socket failed: $reason\n";=0A = return;=0A }=0A # Assign the socket an address=0A if (!bind(S, $this))= {=0A $reason =3D $!;=0A print STDERR "$now: bind failed: $reason\n";= =0A return;=0A }=0A=0A # Connect to the server=0A if (!connect(S,$tha= t)) {=0A $reason =3D $!;=0A print STDERR "$now: connect failed: $reas= on\n";=0A shutdown(S,2);=0A close(S);=0A return;=0A }=0A=0A # El= iminate buffering on this socket=0A select(S); $| =3D 1;=0A=0A # If it'= s a Web service, use the GET method=0A=0A if ($testport =3D=3D 80) {=0A = print S "GET / HTTP/1.0\n\n";=0A eval {=0A local $SIG{ALRM} =3D su= b { die "alarm\n" };=0A alarm 30;=0A $nread =3D sysread S,$buffer= ,10;=0A alarm 0;=0A };=0A if ($@) {=0A $reason =3D "answer = time out";=0A print STDERR "$now: GET / failed: $reason\n";=0A sh= utdown(S,2);=0A close(S);=0A return;=0A }=0A print STDERR "= $now: GET / answered.\n";=0A }=0A=0A print STDERR "$now: Connected succes= sfully.\n";=0A=0A shutdown(S,2);=0A close(S);=0A}=0A=0A --MW5yreqqjyrRcusr Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See for more info. To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org " from the digest: users-digest-unsubscribe@httpd.apache.org For additional commands, e-mail: users-help@httpd.apache.org --MW5yreqqjyrRcusr--