#!/usr/bin/perl # # Copyright (c) 2007, Gregory Fleischer (gfleischer@gmail.com) # # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # 3. The names of the authors may not be used to endorse or promote # products derived from this software without specific prior # written permission. # # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # # # parse the scanfun log file # use strict; my $show_details = 0; my @args = (); foreach my $a (@ARGV) { if ($a =~ /-details?/) { $show_details = 1; } else { push (@args, $a); } } if ($#args > -1) { my $file = shift() or die "missing file"; open(FH, "<", $file) or die "failed to open file ($file): $!"; } else { *FH = *STDIN; } my $addr = undef; while () { chomp; if (/^={32}/) { undef $addr; } elsif (/^addr: (.+)$/) { $addr = $1; } elsif (/^resp: results=(.+)/) { &parse($addr, $1); } } sub parse($$) { my ($addr, $results) = @_; $results =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/gme; my @fields = split(/\|\|/, $results); my ($target, $address, $name, $cname, @ports, %details); foreach my $field (@fields) { if ($field =~ /^t\[(.+)\]/) { $target = $1; } elsif ($field =~ /^a\[(.+)\]/) { $address = $1; } elsif ($field =~ /^n\[(.+)\]/) { $name = $1; } elsif ($field =~ /^c\[(.+)\]/) { $cname = $1; } elsif ($field =~ /^p\((\d+)\):(.*)/s) { push(@ports, $1); $details{$1} = $2; } } if ($#ports > -1) { print "$target, $address, $name, $cname: @ports", "\n"; if ($show_details) { foreach my $p (@ports) { print "==>$p: $details{$p}\n"; } } } } # eof