port file
30 80/tcp closed http 30 443/tcp closed https 30 8080/tcp open http-proxy 50 80/tcp open http 50 443/tcp filtered https 50 8080/tcp filtered http-proxy 70 80/tcp open http 70 443/tcp filtered https 70 8080/tcp filtered http-proxy

IP file
1.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 1.0.0.9 1.0.0.10 1.0.0.11 1.0.0.12 1.0.0.13 1.0.0.14 1.0.0.15 1.0.0.16 1.0.0.17 1.0.0.18 1.0.0.19 1.0.0.20 1.0.0.21 1.0.0.22 1.0.0.23 1.0.0.24 1.0.0.25 1.0.0.26 1.0.0.27 1.0.0.28 1.0.0.29 1.0.0.30 1.0.0.31 1.0.0.32 1.0.0.33 1.0.0.34 1.0.0.35 1.0.0.36 1.0.0.37 1.0.0.38 1.0.0.39 1.0.0.40 1.0.0.41 1.0.0.42 1.0.0.43 1.0.0.44 1.0.0.45 1.0.0.46 1.0.0.47 1.0.0.48 1.0.0.49 1.0.0.50 1.0.0.51 1.0.0.52 1.0.0.53 1.0.0.54 1.0.0.55 1.0.0.56 1.0.0.57 1.0.0.58 1.0.0.59 1.0.0.60 1.0.0.61 1.0.0.62 1.0.0.63 1.0.0.64 1.0.0.65 1.0.0.66 1.0.0.67 1.0.0.68 1.0.0.69 1.0.0.70 1.0.0.71 1.0.0.72 1.0.0.73 1.0.0.74 1.0.0.75 1.0.0.76 1.0.0.77 1.0.0.78 1.0.0.79 1.0.0.80 1.0.0.81 1.0.0.82 1.0.0.83 1.0.0.84 1.0.0.85 1.0.0.86 1.0.0.87 1.0.0.88 1.0.0.89 1.0.0.90 1.0.0.91 1.0.0.92 1.0.0.93 1.0.0.94 1.0.0.95 1.0.0.96 1.0.0.97 1.0.0.98 1.0.0.99

output file
IP port state protocol 1.0.0.29 80/tcp closed http 1.0.0.29 443/tcp closed https 1.0.0.29 8080/tcp open http-proxy 1.0.0.49 80/tcp open http 1.0.0.49 443/tcp filtered https 1.0.0.49 8080/tcp filtered http-proxy 1.0.0.69 80/tcp open http 1.0.0.69 443/tcp filtered https 1.0.0.69 8080/tcp filtered http-proxy


all 14 programs have the same results/output and take the same ARGVs  <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE>

complete list of programs
port-state-service+IP-disk-goto.pl port-state-service+IP-disk-sub.pl # former port-state-servi +ce+IP-disk.pl (above) port-state-service+IP-disk-while.pl port-state-service+IP-mem-list-direct.pl port-state-service+IP-mem-hash-direct.pl port-state-service+IP-mem-array.pl # former port-state-serv +ice+IP-mem.pl (above) port-state-service+IP-mem-array-delete.pl port-state-service+IP-mem-array-delete-xtra.pl port-state-service+IP-mem-hash-direct-delete.pl port-state-service+IP-mem-hash-direct-delete-xtra.pl port-state-service+IP-mem-hash-indirect.pl port-state-service+IP-mem-list-indirect.pl port-state-service+IP-mem-list-splice.pl port-state-service+IP-mem-list-splice-xtra.pl

list of new programs
port-state-service+IP-disk-goto.pl port-state-service+IP-mem-list-direct.pl port-state-service+IP-mem-hash-direct.pl port-state-service+IP-disk-while.pl port-state-service+IP-mem-array-delete.pl port-state-service+IP-mem-array-delete-xtra.pl port-state-service+IP-mem-hash-direct-delete.pl port-state-service+IP-mem-hash-direct-delete-xtra.pl port-state-service+IP-mem-hash-indirect.pl port-state-service+IP-mem-list-indirect.pl port-state-service+IP-mem-list-splice.pl port-state-service+IP-mem-list-splice-xtra.pl


program listing:
port-state-service+IP-disk-sub.pl
die "perl port-state-service+IP-disk-sub.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; } }

port-state-service+IP-disk-goto.pl
die "perl port-state-service+IP-disk-goto.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=$&; goto get_IP; CONT: } } close F0; close F1; close F2; goto END; 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"; goto CONT; } goto CONT; END:

port-state-service+IP-mem-list-direct.pl
die "perl port-state-service+IP-mem-list-direct.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; push @IP,$& 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;

port-state-service+IP-mem-hash-direct.pl
die "perl port-state-service+IP-mem-hash-direct.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;

port-state-service+IP-mem-array.pl
die "perl port-state-service+IP-mem-array.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;

port-state-service+IP-disk-while.pl
die "perl port-state-service+IP-disk-while.pl <INPUT_FILE_ports> <INPU +T_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=$&; 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"; } } } close F0; close F1; close F2;

port-state-service+IP-mem-array-delete.pl
die "perl port-state-service+IP-mem-array-delete.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 ; if (/[0-9]+\//) { $temp = $IP[$line_no - 1] if $IP[$line_no - 1] ne "";$IP[$line +_no - 1] = ""; print F2 $temp, "\t$line\n";$IP[$line_no - 1] = ""; } } close F0; close F2;

port-state-service+IP-mem-array-delete-xtra.pl
die "perl port-state-service+IP-mem-array-delete-xtra.pl <INPUT_FILE_p +orts> <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";$x = $y = 0; 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 ; if ($y > $x) { for ($z = $x;$z < $y;$z++) { delete $IP[$z]; } } if (/[0-9]+\//) { $temp = $IP[$line_no - 1] if $IP[$line_no - 1] ne "";$IP[$line +_no - 1] = ""; print F2 $temp, "\t$line\n";$IP[$line_no - 1] = ""; } $x = $y; } close F0; close F2;

port-state-service+IP-mem-hash-direct-delete.pl
die "perl port-state-service+IP-mem-hash-direct-delete.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 ; $temp = delete $IP{$line_no - 1} if $IP{$line_no - 1}; print F2 $temp, "\t$line\n" if /[0-9]+\//; } close F0; close F2;

port-state-service+IP-mem-hash-direct-delete-xtra.pl
die "perl port-state-service+IP-mem-hash-direct-delete-xtra.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";$x = $y = 0; 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 ; $temp = delete $IP{$line_no - 1} if $IP{$line_no - 1}; $y = $line_no - 1; if ($y > $x) { for ($z = $x;$z < $y;$z++) { delete $IP{$z}; } } print F2 $temp, "\t$line\n" if /[0-9]+\//; $x = $y; } close F0; close F2;

port-state-service+IP-mem-hash-indirect.pl
die "perl port-state-service+IP-mem-hash-indirect.pl <INPUT_FILE_ports +> <INPUT_FILE_IP> <OUTPUT_FILE> " if $#ARGV < 2; sub idx { print F2 $IP{$line_no - 1}, "\t$line\n" if /[0-9]+\//; } 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 ; &idx; } close F0; close F2;

port-state-service+IP-mem-list-indirect.pl
die "perl port-state-service+IP-mem-list-indirect.pl <INPUT_FILE_ports +> <INPUT_FILE_IP> <OUTPUT_FILE> " if $#ARGV < 2; sub idx { print F2 $IP[$line_no - 1], "\t$line\n" } 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; push @IP,$& 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 ; &idx; } close F0; close F2;

port-state-service+IP-mem-list-splice.pl
die "perl port-state-service+IP-mem-list-splice.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; push @IP,$& 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";$temp_IP = "";$y = $z = 0; 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 ; if (/[0-9]+\//) { if ($y != ($line_no - 1)) { $temp_IP = splice(@IP, $line_no - 1 - $z++, 1);$y = $line_ +no - 1; } print F2 $temp_IP, "\t$line\n"; } } close F0; close F2;

port-state-service+IP-mem-list-splice-xtra.pl
die "perl port-state-service+IP-mem-list-splice-xtra.pl <INPUT_FILE_po +rts> <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; push @IP,$& 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";$temp_IP = "";$w = $x = $y += $z = 0; 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 ; if (/[0-9]+\//) { if ($y != ($line_no - 1)) { $temp_IP = splice(@IP, $line_no - 1 - $z++, 1);$y = $line_ +no - 1; splice(@IP, $x - $w, $w = abs($y - $x - $w - 1)); $z += ($y - $x - 1);$x = $y; } print F2 $temp_IP, "\t$line\n"; } } close F0; close F2;


In reply to Re: can't read the 2nd input file;12 new versions of PORT-STATE-SERVICE+IP;14 in all;3 disk,11 memory (part 3) by perl_boy
in thread can't read the 2nd input file by perl_boy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.