Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created September 26, 2012 15:11
Show Gist options
  • Save waffle2k/3788605 to your computer and use it in GitHub Desktop.
Save waffle2k/3788605 to your computer and use it in GitHub Desktop.
This little script pulls a list of IPs from the homepage of a Yahoo! product manager, and creates a list of CIDR ranges that cover the mailserver IPs provided
#!/usr/bin/perl
use strict;
use Net::CIDR::Lite;
# pull the IPs from the following
my @lines = `wget -O- http://public.yahoo.com/~vineet/ip.txt 2>/dev/null`;
# Remove the newline from each row
chomp for @lines;
# Extract just the lines that look like a dotted-quad IP address
my @ips = grep { /^\d+\.\d+\.\d+\.\d+$/ } @lines;
# Instantiate a CIDR object
# http://search.cpan.org/~dougw/Net-CIDR-Lite-0.21/Lite.pm
my $cidr = Net::CIDR::Lite->new;
for my $ip ( @ips ){
# Change the IP into the /24 version
if( $ip =~ /^(\d+\.\d+\.\d+)\.\d+/ ){
# Match the first three octets, append a ".0/24"
my $c = $1 . ".0/24";
$cidr->add( $c );
}
}
$cidr->clean();
print join( "\n", $cidr->list() ), "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment