#!/usr/bin/perl # oNp Parser version 1.0 # This program parses nmap output to search for certian services. # You can choose if you only get ip addresses, hostnames, or both. # It is also able to check for port state, and report accordingly. # usage: onp.pl (-i or -h or -j) (-a or -o)
# # -i give just ip addresses # -h just hostnames # -b give ip addresses with hostnames # -a lists any port state # -o lists only open port state # A DDP production. If you repost this code, plz drop a mention # that I wrote it, and that your NOT ripping it off. Thanks for your time. # http://www.w1nt3rmut3.net ################################################################# # print out usage if needed if ($#ARGV<0) { help(); } $type=$ARGV[0]; $state=$ARGV[1]; $filename=$ARGV[2]; $service=$ARGV[3]; $clsb=$ARGV[4]; $hoststring=$ARGV[5]; # Gotta have input! unless (open (INFILE, "$filename")) { die ("Can't open input file\n"); } # "touch" your file if ($type eq "-i") { if ($state eq "-o") {open (LIST, ">$clsb\_$service\-open.txt");} if($state eq "-a") {open (LIST, ">$clsb\_$service\-any.txt")}; } if ($type eq "-h") { if($state eq "-o") {open (HOST, ">$clsb\_$service\-open.hosts.txt");} if($state eq "-a") {open (HOST, ">$clsb\_$service\-any.hosts.txt")}; } if ($type eq "-b") { if($state eq "-o") {open (BOTH, ">$clsb\_$service\-open.list.txt");} if($state eq "-a") {open (BOTH, ">$clsb\_$service\-any.list.txt");} } # Phat loop while ($line = ) { # Newline destruction chop ($line); # Split up words @words = split(/ /, $line); for ($i=0;$i<= @words;$i++) { #print "$words[$i] \n"; if ($words[$i] =~ /$clsb/) { $ip=$words[$w-1]; $ip=~ s/\)://; $ip=~ s/\(//; # print "$ip \n"; } # need perl for searching for certian words i.e. "nd.edu" # if construction to check for status of $log, then print to file if ($words[$i]=~/$hoststring$/) { $hname=$words[$i]; } # if construction to output if ( ($words[$i] eq $service) && ($state eq "-a") ) { # print "dood\n"; if($type eq "-i") { $wordz += 1; print "ding! on ip $ip\n"; print LIST ("$ip"); } if ($type eq "-h") { $wordz += 1; print "ding! on ip $ip\n"; print HOST ("$hname\n"); $hname=""; } if ($type eq "-b") { $wordz += 1; print "ding! on ip $ip\n"; print BOTH ("$ip"); print BOTH (" $hname\n"); $hname=""; } } if ( ($words[$i] eq $service) && ($state eq "-o") && ($line=~/open/) ) { if($type eq "-i") { $wordz += 1; print "ding! on ip $ip\n"; print LIST ("$ip"); } if ($type eq "-h") { $wordz += 1; print "ding! on ip $ip\n"; print HOST ("$hname\n"); $hname=""; } if ($type eq "-b") { $wordz += 1; print "ding! on ip $ip\n"; print BOTH ("$ip"); print BOTH (" $hname\n"); $hname=""; } } } } $total += $wordz; # tell you what the hell just happened print "total number of occurrences: $total\n"; print "Filename is: "; if ($type eq "-i") { if ($state eq "-o") {print "$clsb\_$service\-open.txt\n\n";} if ($state eq "-a") {print "$clsb\_$service\-any.txt\n\n";} } if ($type eq "-h") { if($state eq "-o") {print "$clsb\_$service\-open.hosts.txt\n\n";} if ($state eq "-a") {print "$clsb\_$service\-any.hosts.txt\n\n";} } if ($type eq "-b") { if($state eq "-o") {print "$clsb\_$service\-open.list.txt\n\n";} if ($state eq "-a") {print "$clsb\_$service\-any.list.txt\n\n";} } sub help { print "error: no ARGV\n\n"; print "oNp Parser\n"; print "This program parses nmap output to search for certian services.\n"; print "You can choose if you only get ip addresses, hostnames, or both \n"; print "It is also able to check for port state, and report accordingly\n\n"; usage(); } sub usage { print "usage: $0 (-i or -h or -b) (-a or -o)
\n\n"; print " -i give just ip addresses\n"; print " -h just hostnames\n"; print " -b give ip addresses with hostnames\n"; print " -a lists any port state\n"; print " -o lists only open port state\n"; exit(-1); }