Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created June 23, 2011 13:27
Show Gist options
  • Save waffle2k/1042526 to your computer and use it in GitHub Desktop.
Save waffle2k/1042526 to your computer and use it in GitHub Desktop.
Using perl to find IPs belonging to a given country code
#!/usr/bin/perl
use strict;
use IP::Country::Fast;
my $reg = IP::Country::Fast->new();
my $input = do { local $/; <>; };
my @ips = $input =~ /(.*?)(?:\/\d+)?\s/sg;
my %cc = map { $_ => $reg->inet_atocc($_) } @ips;
my @chinese = grep { $cc{$_} eq 'CN' } keys %cc;
print join( "\n", @chinese ),"\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment