regex ip address exclusion

Discussion in 'Perl Misc' started by gooofoofs, Apr 27, 2005.

  1. gooofoofs

    gooofoofs Guest

    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);
     
    gooofoofs, Apr 27, 2005
    #1
    1. Advertising

  2. 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
     
    John W. Krahn, Apr 27, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Giambattista Bloisi

    non-blocking mutual exclusion

    Giambattista Bloisi, Dec 16, 2003, in forum: Java
    Replies:
    1
    Views:
    413
    Matt Humphrey
    Dec 16, 2003
  2. Edouard Mercier

    XSD attribute exclusion expression

    Edouard Mercier, Sep 1, 2003, in forum: XML
    Replies:
    4
    Views:
    797
    Edouard Mercier
    Sep 5, 2003
  3. shaun

    xslt, for-each exclusion

    shaun, Aug 16, 2005, in forum: XML
    Replies:
    1
    Views:
    622
    Steve Jorgensen
    Aug 16, 2005
  4. darkhorse

    CGIs and file exclusion

    darkhorse, Nov 4, 2004, in forum: Python
    Replies:
    13
    Views:
    555
    Michele Simionato
    Nov 6, 2004
  5. Replies:
    3
    Views:
    781
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page