in reply to can't read the 2nd input file
IP file WITH SPACEs/TABs and empty NEWLINEs3 80/tcp closed http 3 443/tcp closed https 3 8080/tcp open http-proxy 5 80/tcp open http 5 443/tcp filtered https 5 8080/tcp filtered http +-proxy 7 80/tcp open http 7 443/tcp filtered https 7 8080/tcp filtered http-proxy
1.0.129.197 1.0.131.49 1.0.131.74 1.0.138.143 1.0.138.154 1.0.139.72 1.0.129.191 1.0.129.192 1.0.129.193
1.0.XXX.XXX1.0.XXX.XXX 1.0.0.X 10.00.00.XX 100.000.000.XXX 01.00.00.XX 001.000.000.XXX
1.0.0.X1.0.129.197 1.0.131.49 1.0.131.74 1.0.138.143 1.0.138.154 1.0.139.72 1.0.129.191 1.0.129.192 1.0.129.193
10.00.00.XX1.0.0.0 1.0.0.1 1.0.0.2 1.0.0.3 1.0.0.4 1.0.0.5 1.0.0.6 1.0.0.7 1.0.0.8
100.000.000.XXX10.00.00.00 10.00.00.01 10.00.00.02 10.00.00.03 10.00.00.04 10.00.00.05 10.00.00.06 10.00.00.07 10.00.00.08
01.00.00.XX100.000.000.000 100.000.000.001 100.000.000.002 100.000.000.003 100.000.000.004 100.000.000.005 100.000.000.006 100.000.000.007 100.000.000.008
001.000.000.XXX01.00.00.00 01.00.00.01 01.00.00.02 01.00.00.03 01.00.00.04 01.00.00.05 01.00.00.06 01.00.00.07 01.00.00.08
001.000.000.000 001.000.000.001 001.000.000.002 001.000.000.003 001.000.000.004 001.000.000.005 001.000.000.006 001.000.000.007 001.000.000.008
1.0.0.XIP port state protocol 1.0.131.74 80/tcp closed http 1.0.131.74 443/tcp closed https 1.0.131.74 8080/tcp open http-proxy 1.0.138.154 80/tcp open http 1.0.138.154 443/tcp filtered https 1.0.138.154 8080/tcp filtered http-proxy 1.0.129.191 80/tcp open http 1.0.129.191 443/tcp filtered https 1.0.129.191 8080/tcp filtered http-proxy
10.00.00.XXIP port state protocol 1.0.0.2 80/tcp closed http 1.0.0.2 443/tcp closed https 1.0.0.2 8080/tcp open http-proxy 1.0.0.4 80/tcp open http 1.0.0.4 443/tcp filtered https 1.0.0.4 8080/tcp filtered http-proxy 1.0.0.6 80/tcp open http 1.0.0.6 443/tcp filtered https 1.0.0.6 8080/tcp filtered http-proxy
100.000.000.XXXIP port state protocol 10.00.00.02 80/tcp closed http 10.00.00.02 443/tcp closed https 10.00.00.02 8080/tcp open http-proxy 10.00.00.04 80/tcp open http 10.00.00.04 443/tcp filtered https 10.00.00.04 8080/tcp filtered http-proxy 10.00.00.06 80/tcp open http 10.00.00.06 443/tcp filtered https 10.00.00.06 8080/tcp filtered http-proxy
01.00.00.XXIP port state protocol 100.000.000.002 80/tcp closed http 100.000.000.002 443/tcp closed https 100.000.000.002 8080/tcp open http-proxy 100.000.000.004 80/tcp open http 100.000.000.004 443/tcp filtered https 100.000.000.004 8080/tcp filtered http-proxy 100.000.000.006 80/tcp open http 100.000.000.006 443/tcp filtered https 100.000.000.006 8080/tcp filtered http-proxy
001.000.000.XXXIP port state protocol 01.00.00.02 80/tcp closed http 01.00.00.02 443/tcp closed https 01.00.00.02 8080/tcp open http-proxy 01.00.00.04 80/tcp open http 01.00.00.04 443/tcp filtered https 01.00.00.04 8080/tcp filtered http-proxy 01.00.00.06 80/tcp open http 01.00.00.06 443/tcp filtered https 01.00.00.06 8080/tcp filtered http-proxy
IP port state protocol 001.000.000.002 80/tcp closed http 001.000.000.002 443/tcp closed https 001.000.000.002 8080/tcp open http-proxy 001.000.000.004 80/tcp open http 001.000.000.004 443/tcp filtered https 001.000.000.004 8080/tcp filtered http-proxy 001.000.000.006 80/tcp open http 001.000.000.006 443/tcp filtered https 001.000.000.006 8080/tcp filtered http-proxy
I have tested different forms of Nth IPs with different number of leading '0's (IP port)3 PORT state protocol 3 80/tcp closed http 3 443/tcp closed https 3 8080/tcp open http-proxy 5 80/tcp open http 5 443/tcp filtered https 5 8080/tcp filtered http-proxy 7 80/tcp open http 7 443/tcp filtered https 7 8080/tcp filtered http-proxy
03 80/tcp closed http 003 443/tcp closed https 0003 8080/tcp open http-proxy 005 80/tcp open http 00005 443/tcp filtered https 0000005 8080/tcp filtered http-proxy 0007 80/tcp open http 0000007 443/tcp filtered https 000000007 8080/tcp filtered http-proxy
port-state-service+IP-disk.pldie "perl port-state-service+IP-mem.pl <INPUT_FILE_ports> <INPUT_FILE_ +IP> <OUTPUT_FILE> " if $#ARGV < 2; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=0; while (<F1>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;chomp; $IP[$line_no++] = $& if /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\.[0- +2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } close F1; print F2 "IP\t\tport\tstate\tprotocol\n\n"; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp;/^[0-9]+/;$line=$';$line_no=$&; $line =~ s/^[\t\ ]+//g;$line =~ s/[\t\ ]+$//g ; print F2 $IP[$line_no - 1], "\t$line\n" if /[0-9]+\//; } close F0; close F2;
die "perl port-state-service+IP-disk.pl <INPUT_FILE_ports> <INPUT_FILE +_IP> <OUTPUT_FILE> " if $#ARGV < 2; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$line_stop=0; print F2 "IP\t\tport\tstate\tprotocol\n\n"; while (<F0>) { while (s/^[\ \t]//g) {}; while (s/[\ \t]$//g) {}; s/\r\n//;s/\t+/\t/;chomp; if (/^[0-9]+/) { $line_port=$'; $line_no=$&; &get_IP; } } close F0; close F1; close F2; sub get_IP { while (($line_stop < $line_no) && ($line_IP = <F1>)) { $line_stop++ if $line_IP =~ /[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]\ +.[0-2]?[0-9]?[0-9]\.[0-2]?[0-9]?[0-9]/; } if ($line_stop == $line_no) { $line_IP =~ s/^[\t\ ]+//g;$line_IP =~ s/[\t\ ]+$//g ;$line_IP +=~ s/\n$//g; $line_port =~ s/^[\t\ ]+//g;$line_port =~ s/[\t\ ]+$//g ; print F2 "$line_IP\t$line_port\n"; return; } }
|
|---|