regex ip address exclusion

G

gooofoofs

Im currently using the script below to find lines with valid IP addresses.
Now whats the best way to exclude any IP address in the 10.0.0.0 range.


#!/usr/bin/perl -w
open(FILE, "logfile.log");

foreach $string (<FILE>){


if($string =~ /(\d+)(\.\d+){3}/){
print $string }


}

close(FILE);
 
J

John W. Krahn

gooofoofs said:
Im currently using the script below to find lines with valid IP addresses.
Now whats the best way to exclude any IP address in the 10.0.0.0 range.


#!/usr/bin/perl -w
open(FILE, "logfile.log");

foreach $string (<FILE>){


if($string =~ /(\d+)(\.\d+){3}/){
print $string }


}

close(FILE);

$ perl -e'
use Socket;
for my $addr ( qw/ 1 10000 999999 abcd 1.2.3.4 zzzz 1.2.3.400 10.44.55.66 / ) {
eval { inet_ntoa inet_aton $addr };
if ( $@ ) {
print "$addr is NOT valid.\n";
}
else {
print "$addr is valid";
if ( ( inet_aton( $addr ) & "\xff\0\0\0" ) eq "\x0a\0\0\0" ) {
print " and is in range";
}
print ".\n";
}
}
'
1 is valid.
10000 is valid.
999999 is valid.
abcd is NOT valid.
1.2.3.4 is valid.
zzzz is NOT valid.
1.2.3.400 is NOT valid.
10.44.55.66 is valid and is in range.



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top