in reply to Method to Parse IP 2 Array
Perhaps something like this?
#!/usr/bin/perl use strict; use warnings; while (my $line = <DATA>) { chomp $line; if ($line =~ m/in-addr/) { my @line = split(/\./, $line); if ($line[2] =~m/in-addr/) { process_line("$line[1]\." ."$line[0]\." . "0\." . "0" . " +\/24"); } else { process_line("$line[2]\." . "$line[1]\." ."$line[0]\." . " +0" . "\/16" ); } } else { process_line($line); } } sub process_line { print shift . "\n"; # do whatever... } __DATA__ 250.26.192.in-addr.arpa,3 251.26.192.in-addr.arpa,3 252.26.192.in-addr.arpa,3 253.26.192.in-addr.arpa,3 254.26.192.in-addr.arpa,3 26.192.in-addr.arpa,2 hosangit.com djzah.com
Output
192.26.250.0/16 192.26.251.0/16 192.26.252.0/16 192.26.253.0/16 192.26.254.0/16 192.26.0.0/24 hosangit.com djzah.com
Hope that is helpful....
Insanity: Doing the same thing over and over again and expecting different results...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Method to Parse IP 2 Array
by djzah71 (Initiate) on May 22, 2014 at 23:58 UTC | |
by wjw (Priest) on May 23, 2014 at 02:53 UTC | |
by Anonymous Monk on May 23, 2014 at 00:31 UTC |