#!/usr/bin/perl -w # # $Id: mkhtml.pl,v 1.4 2000/06/29 05:48:45 kjc Exp $ # # usage: mkhtml.pl < tcpdstat_output # mkhtml.pl reads the output of tcpdstat from stdin, and then, # create a html file. # the name of the output html file is ".html", is extracted # from the "Id:" field of the input file. # if there is file named a ".dump" or ".dump.gz", a reference # is created. # # processing rules # ### string ### -->

string

# <<<< text >>>> -->
text
# $tmpfile = "tmp.html"; open(HOUT,"> $tmpfile"); print HOUT "\n"; print HOUT "Traffic Trace Info\n"; print HOUT "\n\n"; print HOUT "\n"; print HOUT "

Traffic Trace Info

\n"; $dontformat = 0; while (<>) { chop; # processing rules # ### string ### -->

string

# <<<< text >>>> -->
text
if ($dontformat) { if (/^>>>>/) { print HOUT ""; $dontformat = 0; } else { # if protocol info, strip level info if (/^\[\d+\](.*)/) { print HOUT $1 . "\n"; } else { print HOUT $_ . "\n"; } } } elsif (/^<<<"; $dontformat = 1; # don't format after this line } elsif (s/^###\s+(.+)###/$1/) { # if starts with "###", it is a heading print HOUT "

" . $_ . "

\n"; # special handling after "Protocol" if (/^Protocol/) { print HOUT "\"[protocol\n"; print HOUT "

"; } # special handling after "Packet Size Distribution" if (/^Packet Size Distribution/) { print HOUT "\"[packet
\n"; print HOUT "detailed numbers
\n"; } } elsif (/([^:]+):(.*)/) { # if ":" exists, use bold typeface print HOUT "" . $1 . ":" . $2 . "
\n"; # find Id field if (/^Id:\s*(\w+)/) { $id = $1; $outfile = $id . ".html"; } } else { # just output the original line print HOUT $_ . "
\n"; } } # if there is a dumpfile, create a link $dumpfile = ""; if (-r $id . ".dump.gz") { $dumpfile = $id . ".dump.gz"; } elsif (-r $id . ".dump") { $dumpfile = $id . ".dump"; } if ($dumpfile) { ($dc, $dc, $dc, $dc, $dc, $dc, $dc, $size) = stat $dumpfile; $sizestr = sprintf "%.2f", $size / 1024 / 1024; # create anonymous ftp url # the path starts at "/pub/" for anon ftp chop($hostname = `hostname`); chop($cwd = `pwd`); if ($cwd =~ /.*(\/pub\/.*)/) { $cwd = $1; } $url = "ftp://" . $hostname . $cwd . "/" . $dumpfile; print HOUT "tcpdump file: $dumpfile ($sizestr MB)
\n"; } print HOUT < EOF close(HOUT); rename $tmpfile, $outfile; exit 0;