Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

regex ip address exclusion
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);



Report this thread to moderator Post Follow-up to this message
Old Post
gooofoofs
04-27-05 08:57 AM


Re: regex ip address exclusion
gooofoofs 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

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
04-27-05 08:57 AM


Re: regex ip address exclusion
gooofoofs (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
";

Report this thread to moderator Post Follow-up to this message
Old Post
Abigail
04-28-05 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:28 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.