Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created February 2, 2010 21:05
Show Gist options
  • Save waffle2k/293029 to your computer and use it in GitHub Desktop.
Save waffle2k/293029 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use Net::CIDR::Lite;
use Getopt::Std;
my %options=();
my $cidr = Net::CIDR::Lite->new;
getopts("n:f:",\%options);
if( defined $options{f} ){
open FD, "<$options{f}" or die("Cannot open $options{f}: $!\n" );
while( <FD> ){
chomp;
$cidr->add( $_ );
}
} else {
die("You must specify a cidr address with -n\n" ) unless defined $options{n};
$cidr->add( $options{n} );
}
while( <> ){
my $ip = $1 if /\b(\d+\.\d+\.\d+\.\d+)\b/;
print if $cidr->find( $ip );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment