#!/usr/bin/perl -wT # # check proxy # # syntax: # ./check_proxy --host= --port= [--url=] # # jorg@wirelessleiden.nl - 18 april 2004 use strict; use Getopt::Long; use LWP::UserAgent; # # settings # my $host = ""; my $port = 3128; my $url = "http://www.trracer.com/wleiden_check.txt"; my $okcode = "EEJ-OKAY"; my $errorcode = 0; GetOptions("hostname:s" => \$host, "port:s" => \$port, "url:s" => \$url); my $ua = new LWP::UserAgent; $ua->proxy(http => "http://$host:$port"); my $request = new HTTP::Request ("GET", "$url"); my $page = $ua->request($request)->as_string; my @line = split(/\n/, $page); if (! defined $line[0]) { print "No response.\n"; exit 2; } if (($line[0] eq "HTTP/1.0 503 Service Unavailable") || ($line[0] eq "HTTP/1.0 404 Not Found")) { $errorcode = 1; print "$line[0]\n"; } elsif ($line[0] !~ /HTTP\/1\.. 200 OK/) { $errorcode = 2; print "$line[0]\n"; } elsif ($line[$#line] !~ $okcode) { $errorcode = 1; print "Got wrong page?\n"; } else { print "$line[0]\n"; } # # exit # (0=ok 1=warning 2=critical 3=unknown 4=dependent) # exit $errorcode;