Created
June 23, 2011 13:27
-
-
Save waffle2k/1042526 to your computer and use it in GitHub Desktop.
Using perl to find IPs belonging to a given country code
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 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