Perl Bulk Query IP Attribution method code _perl

Source: Internet
Author: User
Tags current time

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/;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.