in reply to Match only certain IP Addresses
You don't really say what you IP range is, but I'll use for example the network 192.168.20.0 with a netmask of 255.255.255.0. This will weed out addresses only in this network, sort them numerically, and print them out.my $ips; while(<INPUT>){ if (/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/{ push @ips, $1; } }
use Socket; my $mask = 24; # 255.255.255.0 -> 24 bit netmask my $network = inet_aton("192.168.20.0"); my @myips; foreach $ip ( @iplist ) { $ip = inet_ntoa($ip); # convert ascii to decimal if( ($ip & $mask) == ($network & $mask) ){ push @myips, $ip; } } # this will sort the list properly since it's sorting the numbers. # otherwise it would sort 192.168.20.20 before 196.168.20.3 @myips = sort @myips; foreach $ip ( @myips ) { # print out the ascii format print inet_ntoa($ip), "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Match only certain IP Addresses
by zengargoyle (Deacon) on Aug 06, 2003 at 22:02 UTC | |
|
Re: Re: Match only certain IP Addresses
by bobn (Chaplain) on Aug 07, 2003 at 06:41 UTC |