#!perl
# make a list of Amazon AWS/EC2 IP addresses
# aggregate all the CIDRs
use strict;
use NetAddr::IP;
use HTTP::Cookies;
use LWP::UserAgent;
my $jar = HTTP::Cookies->new(hide_cookie2 => 1);
my $ua = LWP::UserAgent->new(timeout => 30,
cookie_jar => $jar);
my %OPTS = @LWP::Protocol::http::EXTRA_SOCK_OPTS;
$OPTS{SendTE} = 0;
@LWP::Protocol::http::EXTRA_SOCK_OPTS = %OPTS;
my $res = $ua->get('https://forums.aws.amazon.com/ann.jspa?annID=1701');
my $loc;
my %cidr;
for my $line (split /\n/, $res->decoded_content){
if( $line =~ m#^(.+\(.+\))\s*:\s*
# ){
$loc = $1;
}elsif( $line =~ m#^
\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2})# ){
my $net = $1;
push @{$cidr{$loc}}, NetAddr::IP->new($net);
}
}
for my $loc (keys %cidr){
for my $net ( NetAddr::IP::compact(@{ $cidr{$loc} }) ){
printf("%-16s # AWS %s\n", $net, $loc);
}
print "\n";
}