#!/usr/local/bin/perl # library in /usr/local/lib/perl5, access by viewing @INC # # ping2html # # Perl script. written Warren Kibbe, 1996, 1997 # WAKibbe@nwu.edu # # version 1.0 release 2 # last changed 01/30/97. # # Perl script for taking output from "ping.sh" UNIX shell script and converting it to # an html formatted set of documents. Will parse files named "pingxxx.xxx.xxx" where # xxx.xxx.xxx is the subnet name(s) set in the associative array "%subnets" defined # in this perl script. require "ctime.pl"; # require ":Net:Ping.pm"; require "timelocal.pl"; require "wwwdates.pl"; # use Net::Ping; use Config; if ($Config{'osname'} =~ /^macos/i) { # do mac specific stuff here &MacPerl'Quit(1); #quit if a stand alone app $srcpath = "pub:www:rawping:"; $destpath = "pub:www:www:nunet:"; # $inmacintosh = 0; @fileAttributes = ("R*ch", "TEXT"); $nativedirchar=":"; # throw the logs in the working directory $logfile = "ping->html.log"; $errlogfile ="ping->htmlErrs.log"; } else{ $srcpath = "/home/u1/kibbe/ping/"; $destpath = "/home/u1/kibbe/ping/"; $nativedirchar="/"; $logfile = $ENV{'HOME'}.":ping->html.log"; $errlogfile = $ENV{'HOME'}.":ping->htmlErrs.log"; } $subnetseparator=", "; # separator for listing subnets by physical location $debugmode=0; # turn on debugging output $datepattern="ping started at (\.\+)"; $master_file="subnets.html"; $dnsnames = "dns names cache"; %subnets= ( "165.124.9", "645 N. Michigan", "165.124.12", "Health Sciences Building", "165.124.15", "Health Sciences Building", "165.124.18", "Wieboldt?", "165.124.23", "Preventive Medicine?", "165.124.27", "OHC", "165.124.47", "Tarry", "165.124.48", "Searle", "165.124.50", "Ward", "165.124.55", "Ward", "165.124.58", "Tarry", "165.124.71", "Tarry", "165.124.100", "Tarry", "165.124.101", "Tarry", "165.124.102", "Tarry", "165.124.103", "Searle", "165.124.111", "Ward", "165.124.123", "Searle", "165.124.124", "Ward", "165.124.125", "Searle", "165.124.220", "Tarry", "165.124.221", "Searle", "165.124.222", "Tarry", "165.124.225", "Ward", "165.124.229", "Tarry", "165.124.230", "Searle", "165.124.232", "Tarry", "165.124.233", "Tarry", "165.124.234", "Searle", "165.124.235", "Medicine?", "165.124.242", "Ward", "165.124.243", "Searle", "165.124.245", "Tarry", "165.124.247", "Searle", "165.124.253", "Ward", "129.105.72", "BIRL", ); %monthabbrev = ("Jan", 1,"Feb",2, "Mar", 3,"Apr",4,"May", 5,"Jun",6, "Jul",7, "Aug", 8,"Sep", 9,"Oct", 10,"Nov", 11,"Dec", 12); open (LOG,">>".$logfile) || &Die("Unable to open $logfile"); close(STDERR); open(STDERR,">>".$errlogfile) || &Die("Unable to open $errlogfile"); select(STDERR); $| = 1; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $mon++; if($min >= 10) { print LOG "ping->html.pl: started at $mon/$mday/$year $hour:$min\n"; } else { print LOG "ping->html.pl: started at $mon/$mday/$year $hour:0$min\n"; } if (open (DOMAINS, "$srcpath$dnsnames")) { while () { chop; ($ipaddress, $dnsname) = split(/\t/); $dnsname{$ipaddress} = $dnsname; } close DOMAINS; } else { print LOG "\nCannot read from DNS names file $dnsnames!"; print LOG "\n$srcpath"; } open (MFH, ">$destpath$master_file") or die "Error - could not open $master_file $!"; print (MFH "DNS/PING for NUMS subnets\n\n"); print MFH "
\n\"Basic\n
\n"; print MFH "

DNS/PING and Usage Stats for NUMS subnets

\n"; $usageinfo = "

Current bandwidth usage charts:

\n"; $usageinfo .= "\n"; $currenttime=&ctime(time); print MFH "
\n"; print MFH "
To check an IP address for a DNS entry (or get an IP number for a name), enter the number here
"; print MFH "\n"; print MFH "nslookup:\n\n

\n"; print MFH "

NSG | TSS | "; print MFH "NUMS Network Administrators

\n"; print MFH "This page was generated at $currenttime

\n"; print MFH "Contact Warren Kibbe to add other subnets or "; print MFH "to obtain the scripts used to generate these pages. (ping results were generated using UNIX 'sh' shell "; print MFH "script. The Perl5 script ping2html was "; print MFH "used to format DNS and ping data to html."; print MFH "CyberGauge(TM) by Neon Software was used to generate the usage charts)

\n"; print MFH "Copyright (c) 1996, Warren Kibbe and Northwestern University. All rights reserved

\n"; print MFH "Disclaimer

\n\n\n"; close (MFH); open (MFH, "<$destpath$master_file") or die "Error - could not open $master_file $!"; open (DUPFH, ">".$destpath."index.html") or die "Error - could not open index.html for duplicating! $!"; while () { print DUPFH $_; } close (MFH); close (DUPFH); if ($Config{'osname'} =~ /^macos/i) { # do mac specific stuff here MacPerl::SetFileInfo(@fileAttributes, "$destpath$master_file"); MacPerl::SetFileInfo(@fileAttributes, $destpath."index.html"); } # write out all the domain names to save looking them up again if (open (DOMAINS, ">$srcpath$dnsnames")) { foreach $ipaddress (keys(%dnsname)) { print DOMAINS "$ipaddress\t$dnsname{$ipaddress}\n"; } close DOMAINS; if ($Config{'osname'} =~ /^macos/i) { MacPerl::SetFileInfo(@fileAttributes, "$dnsnames"); } } else { print LOG "\nCannot write to DNS names file $dnsnames\n"; print STDERR "\nCannot write to DNS names file $dnsnames\n"; } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $mon++; if($min >= 10) { print LOG "finished at $mon/$mday/$year $hour:$min\n\n\n"; } else { print LOG "finished at $mon/$mday/$year $hour:0$min\n\n\n"; } close(LOG); close(STDERR); if ($Config{'osname'} =~ /^macos/i) { # do mac specific stuff here MacPerl::SetFileInfo(@fileAttributes, $logfile); MacPerl::SetFileInfo(@fileAttributes, $errlogfile); } sub addname { local($ip) = $_[0]; undef $domain; local($dnsentry); # if this is already a DNS name (as opposed to IP address) # then nothing to look up - the punter is wasting my time! if ($ip =~ /[A-Z]/i) { # domain = last word of dns name (e.g. lse.ac.uk -> uk) ($dnsentry)=$ip; ($domain) = $ip =~ /(\w+)$/; } # if domain name for this ip address not yet known, look it up else { if (!$dnsname{$ip} || $dnsname{$ip} eq "**unregistered**") { # if lookup fails, set to "**unregistered**" if ($ip =~ /^\s*((\d+\.){3}\d+)\s*$/) { $packedip = pack ('C4', split (/\./, $1)) } else { $packedip = (gethostbyname($ip))[4] } ($dnsentry) = (gethostbyaddr($packedip, 2))[0]; $dnsentry =~ tr/A-Z/a-z/; # convert dns name to lowercase if ($dnsentry eq '') { $dnsentry = "**unregistered**"; } $dnsname{$ip} = $dnsentry; } else { # domain = last word of dns name (e.g. lse.ac.uk -> uk) ($dnsentry)=$dnsname{$ip}; ($domain) = $dnsname{$ip} =~ /(\w+)$/; } } $dnsentry; } # &addname sub gettimezoneadj { local($now)=time; local($nowdiff)=time-localtime; print "gettimezoneadj: time-localtime = ".$nowdiff/(60*60*24)." hours \n" if $debugmode; local(@nowgm)=gmtime($now); local(@nowlocal)=localtime($now); # (secs mins hours days months-1 years) local($timeadj)=(($nowgm[3]-$nowlocal[3])*24)+($nowgm[2]-$nowlocal[2]); $timeadj } # -------------------------------------------------------------------------- sub bysubnet { # compare by ip address in order to sort into # order by ip address or domain local($comp) = 0; local($dnsa) = 0; local($dnsb) = 0; if ($a =~ /[A-Z]/i) { # $a is a DNS name if ($b =~ /[A-Z]/i) { # $a and $b are both DNS names $dnsa = join('.', reverse(split(/\./, $a))); $dnsb = join('.', reverse(split(/\./, $b))); $comp = $dnsa cmp $dnsb; } else { # $dnsa is a DNS name but $dnsb is an IP address $comp = -1; } } elsif ($b =~ /[A-Z]/i) { # $dnsa is an IP address but $dnsb is a DNS name $comp = +1; } else { # #$dnsa and $dnsb are both IP addresses ($a1, $a2, $a3, $a4) = split(/\./, $a); ($b1, $b2, $b3, $b4) = split(/\./, $b); $comp = $a1 <=> $b1; $comp = $a2 <=> $b2 if $comp == 0; $comp = $a3 <=> $b3 if $comp == 0; } return $comp; } 1; __END__ :endofperl