For business needs, to query the customer's IP address, will be part of the region's customers filtered out, began to think of the use of IP database, found that the difficulty of reading the pure database for me some of the big, and my current time requirements are more urgent, through the group of inquiries, thanks to Black Shadow and help Kay, recommended Ip::qqwry: :D ecoded This module, which is designed to read the Qqwry pure database, is very simple to use.
Copy Code code as follows:
#!/usr/bin/perl
Use Ip::qqwry::D ecoded;
Use Encode;
Use UTF8;
Binmode (STDIN, ': Encoding (UTF8) '); #这三行
Binmode (STDOUT, ': Encoding (UTF8) '); #抄别人的
Binmode (STDERR, ': Encoding (UTF8) '); #用来输出中文, and take Chinese to find
My $qqwry =ip::qqwry::D ecoded->new (' Qqwry.dat ', ' GBK ');
Open Unuse, ' iplist.txt ';
while (<UNUSE>) {
($id, $ip, $key) =/(\d+) \s+ (. *?) \s+ (. *)/;
My $info = $qqwry->query ("$ip"); #其实关键代码就这一行, haha
printf "%s\t%s\t%s\n", $id, $ip, $key if $info =~/region name/;
}