#c:\\perl\\bin #coded for Windows 2000 by Cpl Steve Taylor 1stMarDiv G-6 DSN 365-3499 use CGI qw(:standard :html3 -no_debug); use Time::CTime; $dir = "c:"; #Directory location of output files $refresh = 10; # Refresh rate of HTML page for browser $hostfile = "c:\\hostlist.txt"; $htmlfile = "linkstat.html"; $pingcnt = "2"; open(HOSTLIST, $hostfile) || die "Couldn't open $hostfile: $!"; @hostlist = ; close(HOSTLIST); open(HTMLOUT, ">$dir\\$htmlfile") || die "Couldn't open $dir\\$htmlfile: $!"; print HTMLOUT "1st Marine Division Link Status", "", ""; print HTMLOUT "

1st Marine Division Link Status

"; @headings = ('Node', 'Description', 'Status'); @rows = th(\@headings); foreach (@hostlist) { chomp; /:/ || next; # Check for colon to be sure this is not a blank line ($host, $desc) = split(/:/); $pingout = `c:\\winnt\\system32\\ping -n $pingcnt $host 2>&1`; # grab the ping STDOUT and STDERR open(PINGOUT, ">$dir\\$host.html") || die "Couldn't open $dir\\$host.html: $!"; $time = ctime(time()); print PINGOUT start_html(-BGCOLOR=>'white', -TEXT=>'black', -title=>"Results of ping execution for $host"), h1("Results for $host at $time"), p($desc); foreach (split(/\n/, $pingout)) { print PINGOUT $_ . br; } print PINGOUT end_html(); close(PINGOUT); $host = a({-href=>"$host.html"}, "$host"); if($pingout =~ /unknown host/) { # This never shows when an IP is not resolved push(@rows, td([$host, $desc, "Unresolved IP"])); } elsif($pingout =~ /100% packet loss/) { push(@rows, td([$host, $desc, "Down"])); } else { push(@rows, td([$host, $desc, "Running"])); } } $time = ctime(time()); print HTMLOUT table({-border=>undef}, caption("Status check as of $time"), Tr(\@rows)); print HTMLOUT a({-href=>"mailto:webmaster\@1mardiv.usmc.mil"}, "webmaster\@1mardiv.usmc.mil"); print HTMLOUT end_html(); close(HTMLOUT);