Created
September 26, 2012 15:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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