Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Network Link Status Report Generator

by Big Willy (Scribe)
on Mar 27, 2001 at 04:00 UTC ( #67388=sourcecode: print w/replies, xml ) Need Help??
Category: Networking Code
Author/Contact Info Will Stockwell ( Big Willy at
Description: Generates an HTML report of ping tests for connectivity to the hosts in 'hostfile,' while is formatted as such:


Useful for admins who want to have a cron job intermittently check link status for router-router links, etc. Realize that if you can't ping the host, but can access it by other means this script will not work.
#!/usr/bin/perl -w
# coded by Will Stockwell(

use CGI qw(:standard :html3 -no_debug);
use Time::CTime;

$dir = "."; #Directory location of output files
$refresh = 120; # Refresh rate of HTML page for browser
$hostfile = "hostlist";
$htmlfile = "linkstat.html";
$pingcnt = "3";

open(HOSTLIST, $hostfile) || die "Couldn't open $hostfile: $!";
@hostlist = <HOSTLIST>;

open(HTMLOUT, ">$dir/$htmlfile") || die "Couldn't open $dir/$htmlfile:
+ $!";

print HTMLOUT "<HTML><HEAD><TITLE>Link Status</TITLE>",
              "<META HTTP-EQUIV='refresh' CONTENT='$refresh; '>",
              "</HEAD><BODY BGCOLOR='lightblue' TEXT='black'>",
              h1("Link Status");

@headings = ('Node', 'Description', 'Status');
@rows = th(\@headings);

foreach (@hostlist) {
        /:/ || next; # Check for colon to be sure this is not a blank 
        ($host, $desc) = split(/:/);
        $pingout = `/sbin/ping -c $pingcnt $host 2>&1`; # grab the pin
        open(PINGOUT, ">$dir/$host.html") || die "Couldn't open $dir/$
+host.html: $!";
        $time = ctime(time());
        print PINGOUT start_html(-BGCOLOR=>'lightblue',
                                -title=>"Results of ping execution for
+ $host"),
                                h1("Results for $host at $time"),
        foreach (split(/\n/, $pingout)) { print PINGOUT $_ . br; }
        print PINGOUT end_html();
        $host = a({-href=>"$host.html"}, "$host");

        if($pingout =~ /unknown host/) { # This never shows when an IP
+ is not resolved
            push(@rows, td([$host, $desc, "<FONT COLOR='brown'>Unresol
+ved IP</FONT>"])); 
        } elsif($pingout =~ /100% packet loss/) {
            push(@rows, td([$host, $desc, "<FONT COLOR='red'>Down</FON
        } else {
            push(@rows, td([$host, $desc, "<FONT COLOR='green'>Running

$email = a({-href=>"mailto:waldo\"}, "waldo\@cyberspace");
$time = ctime(time());

print HTMLOUT table({-border=>undef}, caption("Status check as of $tim
+e"), Tr(\@rows));
print HTMLOUT h5("Generated by, coded by Will Stockwell($e
print HTMLOUT end_html();

Replies are listed 'Best First'.
Re: Network Link Status Report Generator
by idnopheq (Chaplain) on Apr 04, 2001 at 14:46 UTC
    Interesting. I would, however, seriously consider removing the dependency on the external ping command and use Net::Ping. I think it would be safer, likely faster, and takes care of ping's root requirement on some platforms.

    Try liberating the appropriate parts of the ping script from PPT.

    You need to ensure you have a current version of Net::Ping, so you can choose your ping type (TCP, UDP, or ICMP).


      As I see it with Net::Ping you'd still be forced to run it as su (unless you run echo service from (x)inetd).
      It's all in the documentation... Also, Net::Ping doesn't provide the same kind of output as system ping, unless you want to twiddle with timers and timeouts.
      I'd say that it would be neater here to use "open(|/sbin/ping <opts>)".
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://67388]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2018-05-26 04:52 GMT
Find Nodes?
    Voting Booth?