#!/usr/local/bin/perl ############################################################################# ## ## Ping/traceroute CGI ## ## Copyright (C) 1997 Chris Johnson (sixie@nccnet.co.uk) ## ############################################################################# ## ## This is an all in one thing...no seperate HTML page needed!! Just place ## this in your cgi-bin directory and your away :-) ## ############################################################################# require '/usr/local/httpd/cgi-bin/cgi-lib.pl'; print &PrintHeader; print ''; print ''; print 'Ping/Traceroute Gateway'; print ''; print ''; if (&MethGet) { print ''; print '

Ping/Traceroute Gateway

'; print 'This is a gateway for ping and traceroute - it will allow you '; print 'to see if a host on the internet is up, and optionally will '; print 'return the route.'; print '
'; print 'Host to check:
'; print ' Ping site
'; print ' Trace the '; print 'route (note, traceroutes can take some time to respond, '; print 'especially if the route is busy or long!)

'; print ' '; print ''; print '

'; } else { &ReadParse(*input); $site = $input{SITE}; $query = $input{QUERY}; if ( $site eq "" ) { print '

Sorry,

'; print '...but you need to enter a name of a site to try and'; print 'contact. Please '; print "try again..."; print ''; exit 0; } if ( $query eq "" ) { print '

Sorry,

'; print '...but you need to enter a query type.'; print 'Please '; print "try again..."; print ''; exit 0; } $site =~ s/[^0-9A-Za-z.-]//g; if ( $query eq "ping") { print '

Ping gateway

'; print "Checking to see if $site is active...
\n"; system("/bin/ping -c 1 $site > /dev/null 2>&1"); wait(); $code = $? / 256; if ( $code == 0 ) { print "Host $site is up"; } else { if ( $code == 1 ) { print "Host $site is not responding"; } else { if ( $code == 2 ) { print "Host $site is not known"; } else { print "Unknown error contacting $site"; } } } print "

\n"; } else { ## All this gubbins is to get the output correct...see the ## apache FAQ... local ($oldbar) = $|; $cfh = select (STDOUT); $| = 1; print '

Traceroute gateway

'; print "Tracing route to $site...
\n"; print '
';
		$| = $oldbar;
		select ($cfh);

		system ("/usr/sbin/traceroute $site 2>&1");
		wait();
		print '
'; print 'Done.

'; print '


How to read a traceroute

'; print 'Each host along the route is checked 3 times for a '; print 'response. The response time is given in milliseconds. '; print 'A * indicates that the listed host failed to respond.

'; print 'Other things you may see include:

'; print 'The last two should not occour. If they '; print 'do, then you have just found a broken gateway - '; print 'congratulations!

'; } } print '


CGI created by Chris Johnson (Sixie)'; print '';