Code Comments
Programming Forum and web based access to our favorite programming groups.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);
Post Follow-up to this messagegooofoofs wrote:
> 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
--
use Perl;
program
fulfillment
Post Follow-up to this messagegooofoofs (fsjfjs@nospma.net) wrote on MMMMCCLVII September MCMXCIII in
<URL:news:d4n22c$bkt$1@news-01.bur.connect.com.au>:
<> Im currently using the script below to find lines with valid IP addresse
s.
<> 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 }
use Regexp::Common;
/(?<!\d)(?!10)$RE{net}{IPv4}(?!\d)/
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker
";
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.