perl_boy has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm failling to read the 2nd input file in citrix-enum-apps-xml-PORT-STATE-SERVICE+IP-disk.pl in the while loop line 11
die "perl citrix-enum-apps-xml-PORT-STATE-SERVICE+IP-disk.pl <INPUT_FI +LE_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; while (<F0>) { s/\r\n//; /^[0-9]+/; $line=$'; $line_no=$&; while (<F1> && $line_stop++ < $line_no) { s/\r\n//; } print F2 $_, "\t$line\n" if /[0-9]+\//; } close F0; close F1; close F2;
I have tried to replace that line 11 with
while (<F1> && $line_stop++ < $line_no) { s/\r\n//;print $_; }
but nothing comes out what's wrong ? Remember I have already one input file openned F0 the idea of the script is to replace the line number (3 and 5 here) in port.txt input file
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
and get the IP corresponding to the nth ($line_stop) (3 and 5 here) IP by 1.0.131.74 and 1.0.138.154
1.0.129.197 1.0.131.49 1.0.131.74 1.0.138.143 1.0.138.154 1.0.139.72
to produce
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
any ideas ? thank's

Replies are listed 'Best First'.
Re: can't read the 2nd input file (updated)
by haukex (Archbishop) on Mar 15, 2021 at 18:21 UTC

    You need to check your open calls for errors, as shown in "open" Best Practices - once you've got a more specific error message, we can help better. (And if you're not already, Use strict and warnings!)

    Update: While what I wrote above is correct, looking at your code again, there are further issues: after while (<F1> ... reads the input file, it doesn't automatically reset to the beginning of the file. Also, since you're not using the while (<F1>) form and instead have added additional conditionals in the while condition, Perl is not going to assign the current line to $_ for you like it is with while (<F0>). And another thing I see is that you never reset $line_stop.

    So overall, because even I am having a bit of trouble understanding what your code is supposed to be doing, I think you'll need to take a step back and rethink your logic. Note that instead of nested loops, a common approach is to first read one of the files into a hash (or other data structure), and then use that for lookups while looping over the other file. I would suggest you take a look at perlintro and the Basic debugging checklist.

    Update 2: Here's a suggestion: You can read the list of IP addresses into an array by simply saying chomp( my @ips = <$ip_filehandle> ); (see also chomp). Then, in a basic while loop, read the lines of the file with the port specifications, and you can then select the IP address from the array - remember that arrays are indexed starting from 0, while your lines appear to be numbered starting from 1.

Re: can't read the 2nd input file
by haukex (Archbishop) on Mar 15, 2021 at 20:02 UTC

    Since you provided your code and sample input and output data, I'll give you some code to get you started:

    #!/usr/bin/env perl use warnings; use strict; use Data::Dumper; # for debugging $Data::Dumper::Useqq=1; my $DEBUG = 1; die "Usage: $0 <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE>" if @ARGV!=3; my ($PORTS_FILE, $IPS_FILE, $OUT_FILE) = @ARGV; open my $ip_fh, '<:crlf', $IPS_FILE or die "$IPS_FILE: $!"; chomp( my @ips = <$ip_fh> ); close $ip_fh; print Data::Dumper->Dump([\@ips], ['*ips']) if $DEBUG; open my $out_fh, '>', $OUT_FILE or die "$OUT_FILE: $!"; open my $port_fh, '<:crlf', $PORTS_FILE or die "$PORTS_FILE: $!"; my $header = <$port_fh>; while ( my $line = <$port_fh> ) { chomp($line); my ($line_nr,$rest) = $line =~ /^(\d+)(\s+.+)$/ or die "Failed to parse line: $_"; print Data::Dumper->Dump([$line_nr,$rest], [qw/line_nr rest/]) if $DEBUG; die "Invalid line number: $line_nr" if $line_nr < 1 || $line_nr > @ips; my $ip = $ips[ $line_nr - 1 ]; print Data::Dumper->Dump([$ip], ['ip']) if $DEBUG; print {$out_fh} $ip, $rest, "\n"; } close $port_fh; close $out_fh;

    Note that this makes a few small assumptions:

    • It doesn't validate the list of IP adresses. You could do that with, for example, Regexp::Common::net.
    • This code assumes the ports list will always have a header line. If that's not always the case, you could check for the header line inside the while loop using a regular expression, perhaps in combination with the special variable $., and skip the current iteration of the loop with next.
    • Because your code includes s/\r\n//, I am guessing that your input file has CRLF line endings and you're processing it on a *NIX OS. Adding the :crlf PerlIO layer will convert those CRLFs for you, so that's what I've done, and it'll leave a file that already has only LF line endings unchanged. The output file in this code will have LF line endings on *NIX, but you could also add the :crlf layer in that open as well to get CRLF.
      Sorry for the detail. I'v complete forgotten this program as another guy on the job found a similar program. I stumble on this forgotten program as I was sorting out files.
      the memory version reads the IP file and into memory and prints the IP from the array to the output file
      the disk version reads a files at once, altering from one file to the other until it find the numbered IP then write the IP and associated ports to the output file.
      the memory version is much faster and thus much easier to write but may not work on computers with less memory. the disk version is much slower due to frequent disk access.
      port-state-service+IP-mem.pl and port-state-service+IP-disk.pl https://www.perlmonks.com/?node_id=11129698
      thank you for your help.
Re: can't read the 2nd input file
by tybalt89 (Monsignor) on May 07, 2022 at 21:12 UTC

    NOTE: requires portfile to be in sorted order

    NOTE: The IPfile read should be in the body of the "while", not in the condition.

    NOTE: "goto" not required.

    NOTE: Does not even have to read all the way through the IPfile if no IPs that are near the end are referenced.

    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11129698 use warnings; @ARGV = qw( port.file ip.file out.file); # FIXME only for testing @ARGV == 3 or die "wrong number of arguments"; open $_, '<', shift or die for my( $F0, $F1); open $_, '>', shift or die for my $F2; my ($no, $IP) = 0; while( <$F0> ) # NOTE assumes port file is in sorted order { my ($stop, $port) = /^(\d+)\s+(.*\n)/; $no += ($IP = <$F1> // die) =~ /^(?:\d+\.){3}\d+\s+\z/ while $no < $ +stop; print $F2 $IP =~ s/\s+\z//r, "\t$port"; } close $F2; system 'cat out.file'; # FIXME only for testing

    Outputs (for your larger example with blank lines in the IP file):

    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
Re: can't read the 2nd input file
by perl_boy (Novice) on Feb 01, 2022 at 22:07 UTC
    The port-state-service+IP-mem.pl and port-state-service+IP-disk.pl program has been re-written and ignores SPACEs/TABs within IP and port files,that is a line ONLY containing SPACEs/TABs in the IP file is NOT inserted in the IP array it takes as input via command line arguement ARGV 0,1,2 the port file , the IP file and the output where numbered IPs from the port file are written along with the port,state and protocol.
    The port file contains a number at the left that is intented to pick-up the Nth 0-based IP from the IP file,empty lines are ignored. I have made it on purpose to insert SPACEs/TABs and empty NEWLINEs just to show you that the program takes care of this and bellow the normal IP and port files WITHOUT SPACEs/TABs and empty NEWLINEs.
    The port-state-service+IP-mem.pl was much easier to write and runs much faster than port-state-service+IP-disk.pl but may not work on computers with less memory. On the other hand port-state-service+IP-disk.pl runs with low constant memory but is much slower due to frequent disk access.
    Again, thank you all for your help.

    port file WITH SPACEs/TABs and empty NEWLINEs
    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
    IP file WITH SPACEs/TABs and empty NEWLINEs
    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

    IP file WITHOUT SPACEs/TABs and empty NEWLINEs
    I have tested different forms of IPs (IP file)
    1.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.XXX.XXX
    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.0.X
    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
    10.00.00.XX
    10.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
    100.000.000.XXX
    100.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
    01.00.00.XX
    01.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.XXX
    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

    and have the following output
    1.0.XXX.XXX
    IP 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
    1.0.0.X
    IP 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
    10.00.00.XX
    IP 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
    100.000.000.XXX
    IP 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
    01.00.00.XX
    IP 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
    001.000.000.XXX
    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

    port file WITHOUT SPACEs/TABs and empty NEWLINEs (there are 2 TABs between the line number and the rest of the line)
    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
    I have tested different forms of Nth IPs with different number of leading '0's (IP port)
    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-mem.pl
    die "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;
    port-state-service+IP-disk.pl
    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; } }
Re: can't read the 2nd input file;partial memory via IP start (ARGV 3) using split
by perl_boy (Novice) on Jun 07, 2022 at 12:24 UTC
    I made the following -ARGV-line-IP-start to take an extra command line arguement  <LINE_IP_LINE>  $ARGV[3] as a start line number of the IP file  INPUT_FILE_IP, that add that number when reading it. use this AFTER using split. Just man split for details
    Everything works find with the same test files
    added -ARGV-line-IP-start to the following memory programs filenames
    port-state-service+IP-mem-list-direct.pl port-state-service+IP-mem-hash-direct.pl port-state-service+IP-mem-array.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

    to make
    port-state-service+IP-mem-array-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-indirect-ARGV-line-IP-start.pl port-state-service+IP-mem-array-delete-ARGV-line-IP-start.pl port-state-service+IP-mem-list-direct-ARGV-line-IP-start.pl port-state-service+IP-mem-array-delete-xtra-ARGV-line-IP-start.pl port-state-service+IP-mem-list-indirect-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-ARGV-line-IP-start.pl port-state-service+IP-mem-list-splice-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-delete-ARGV-line-IP-start.pl port-state-service+IP-mem-list-splice-xtra-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-delete-xtra-ARGV-line-IP-start.p +l

    added die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3]<=" if $ARGV[3] =~ /[^0-9]/; to check that the third command line arguement is indeed a JUST number and changed
    line 1
    die "perl port-state-service+IP-mem-array.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> " if $#ARGV < 2;

    to
    die "perl port-state-service+IP-mem-array.pl <INPUT_FILE_ports> <INPUT +_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $#ARGV < 3;

    line 4 in
    port-state-service+IP-mem-array-ARGV-line-IP-start.pl port-state-service+IP-mem-array-delete-ARGV-line-IP-start.pl port-state-service+IP-mem-list-direct-ARGV-line-IP-start.pl port-state-service+IP-mem-array-delete-xtra-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-ARGV-line-IP-start.pl port-state-service+IP-mem-list-splice-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-delete-ARGV-line-IP-start.pl port-state-service+IP-mem-list-splice-xtra-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-direct-delete-xtra-ARGV-line-IP-start.p +l

    line 8 in
    port-state-service+IP-mem-list-indirect-ARGV-line-IP-start.pl port-state-service+IP-mem-hash-indirect-ARGV-line-IP-start.pl

    $line_no=0;
    to $line_no=$ARGV[3];

    here is the program code


    port-state-service+IP-mem-array-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-array-ARGV-line-IP-start.pl <INPUT +_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $#ARGV +< 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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-delete-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-array-delete-ARGV-line-IP-start.pl + <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if +$#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-array-delete-xtra-ARGV-line-IP-sta +rt.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE> +" if $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-hash-direct-ARGV-line-IP-start.pl +<INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $ +#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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-hash-direct-delete-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-hash-direct-delete-ARGV-line-IP-st +art.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE +>" if $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-hash-direct-delete-xtra-ARGV-line- +IP-start.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP +_LINE>" if $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-hash-indirect-ARGV-line-IP-start.p +l <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if + $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; 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=$ARGV[3]; 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-direct-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-list-direct-ARGV-line-IP-start.pl +<INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $ +#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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-list-indirect-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-list-indirect-ARGV-line-IP-start.p +l <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if + $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; 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=$ARGV[3]; 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-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-list-splice-ARGV-line-IP-start.pl +<INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" if $ +#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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-ARGV-line-IP-start.pl
    die "perl port-state-service+IP-mem-list-splice-xtra-ARGV-line-IP-star +t.pl <INPUT_FILE_ports> <INPUT_FILE_IP> <OUTPUT_FILE> <LINE_IP_LINE>" + if $#ARGV < 3; die "ARGV[3] <LINE_IP_LINE> MUST contain just a number: got =>$ARGV[3] +<=" if $ARGV[3] =~ /[^0-9]/; open(F0, $ARGV[0]); open(F1, $ARGV[1]); open(F2, ">$ARGV[2]"); $line_no=$ARGV[3]; 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;

Re: can't read the 2nd input file;12 new versions of PORT-STATE-SERVICE+IP;14 in all;3 disk,11 memory (part 1)
by perl_boy (Novice) on Apr 04, 2022 at 16:32 UTC
    I have made 12 new versions/programs from port-state-service+IP-mem.pl (now renamed port-state-service+IP-mem-array.pl) and port-state-service+IP-disk.pl now renamed port-state-service+IP-disk-sub.pl
    3 versions/programs work from disk
    port-state-service+IP-disk-goto.pl port-state-service+IP-disk-sub.pl port-state-service+IP-disk-while.pl

    11 versions/programs work from memory
    port-state-service+IP-mem-list-direct.pl port-state-service+IP-mem-hash-direct.pl port-state-service+IP-mem-array.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

    The ones operating from disk is in the case where the list is IPs taken from IP.txt file, which may be very big will not fit in a computers memory (some legacy computers from the 70/80 have only 64K!) in which case will work much slower due to frequent disk access
    Those are goto, sub and while.
    The goto version is a bit contreversial and the black sheep since it uses a goto to jump in goto get_IP (line 13) and out goto CONT (line 20) of the outter while (line 7) loop and I was a bit hesitant of including it here,but I did EVERYTHING I could, but could not find any instruction/statement/command to return from a goto (see below) and decided to post it anyway for completeness
    The sub version uses a subroutine calling &get_IP (line 13) defined below (lines 18 .. 28)
    The while version uses an inner while loop (lines 13 .. 15)
    I did the port-state-service+IP-disk-while.pl from port-state-service+IP-disk-goto.pl replacing goto get_IP with the code of that label , indented and deleted the labals get_IP CONT END
    All 3 versions (subroutine calling &get_IP, while loop, goto get_IP label) read the IP.txt file upto the line number 1st column ($1 as in awk) of port.txt file and prints the IP associated with the nth,that is, that number
    The ones operating from memory are much faster since IPs are fetched directly from memory. They use 3 different data structures (array, list, hash) from perl to store IPs read from IP.txt
    list and hash both have a direct and indirect version. The direct version port-state-service+IP-mem-list-direct.pl and port-state-service+IP-mem-hash-direct.pl read from the data structure (list, hash) itself without passing by a subroutine, while the indirect version port-state-service+IP-mem-hash-indirect.pl and port-state-service+IP-mem-list-indirect.pl uses the idx subroutine
    The array and hash both have 2 delete versions
    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

    the delete ONLY versions port-state-service+IP-mem-array-delete.pl and port-state-service+IP-mem-hash-direct-delete.pl delete ONLY the index item while port-state-service+IP-mem-array-delete-xtra.pl and port-state-service+IP-mem-hash-direct-delete-xtra.pl delete items between interveining line numbers from the port.txt file
Re: can't read the 2nd input file;12 new versions of PORT-STATE-SERVICE+IP;14 in all;3 disk,11 memory (part 2)
by perl_boy (Novice) on Apr 06, 2022 at 12:51 UTC
    The list also has 2 splice versions port-state-service+IP-mem-list-splice.pl and port-state-service+IP-mem-list-splice-xtra.pl
    As in the above port-state-service+IP-mem-list-splice.pl delete ONLY the index item while port-state-service+IP-mem-list-splice-xtra.pl delete items between interveining line numbers from the port.txt file
    port-state-service+IP-mem-list-splice.pl calls splice on list @IP this one REALLY caused be headeachs as is I was struggling with a moving target, @IP when calling splice so I have created $w $x $y $z variable to deal with this,which finally works, but NOT WITHOUT effort !
    I have done port-state-service+IP-mem-list-direct.pl from port-state-service+IP-mem.pl (now renamed port-state-service+IP-mem-array.pl) changing $IP[$line_no++] = for push @IP, at line 8
    I have done port-state-service+IP-mem-hash-direct.pl from port-state-service+IP-mem.pl (now renamed port-state-service+IP-mem-array.pl) changing $IP[$line_no++] for $IP{$line_no++} at line 8 and changing $IP[$line_no - 1] for $IP{$line_no - 1} at line 16
    Finally, the plain array version port-state-service+IP-mem-array.pl leaves the array untouched

    A few words on the contreversial goto version port-state-service+IP-disk-goto.pl
    I have posted 11141855 on "how to return from a goto ?" but got no replies as an instruction/statement/command that would allow me to return FROM WITHIN the label,the only reply I got was to goto sub using a subroutine,but this is not a label and is alread listed here (port-state-service+IP-disk-sub.pl)
    I have Google searched for a perl statement to get out of a goto label and resume where it left off and I have read a few files about the goto statement all URLs uploaded here http://bitcoinshell.mooo.com/users/p3rl/URL-00.html but nothing satisfactory
    I have made port-state-service+IP-disk-goto.pl out of port-state-service+IP-disk.pl now renamed port-state-service+IP-disk-sub.pl replacing the subroutine call &get_IP with goto get_IP AND replacing the subroutine with a label
    Althought both programs work fine I m a bit concerned about the above warning messages for jumping in the middle of a while I have fixed this from the outside (shell) using perl port-state-service+IP-disk-goto.pl ports.txt IP.txt output.txt 2> /dev/null redirecting STDERR to /dev/null
    using the 2> bash shell operator
    I have even tested with a large list of IPs in addition to those listed on 11129698 under "IP file WITH SPACEs/TABs and empty NEWLINEs", "IP file WITHOUT SPACEs/TABs and empty NEWLINEs" and "and get the IP corresponding to the nth", "I have tested different forms of Nth IPs with different number of leading '0's (IP port)" for the purpose of port-state-service+IP-disk-goto.pl (warnings being thorws up to STDERR) and port-state-service+IP-mem-list-splice-xtra.pl delete items between interveining line numbers in the @IP list and both work fine (see output file below)

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 (Novice) on Apr 07, 2022 at 12:21 UTC
    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;

A reply falls below the community's threshold of quality. You may see it by logging in.