Perl method code for batch querying IP address locations

Source: Internet
Author: User

Due to business needs, to query the customer's IP address and filter out customers in some regions, I began to think of using the IP database. It was a little difficult for me to read pure databases, however, my current time requirements are quite urgent. By asking in the group, I would like to thank the hacker and Fu Kai for their help. I recommend the IP: qqwry: decoded module, this module is designed to read pure qqwry databases, which is very easy to use.

CopyCodeThe Code is as follows :#! /Usr/bin/perl
Use IP: qqwry: decoded;
Use encode;
Use utf8;
Binmode (stdin, ': encoding (utf8)'); # these three rows
Binmode (stdout, ': encoding (utf8)'); # copy others'
Binmode (stderr, ': encoding (utf8)'); # used to output Chinese characters and search for Chinese Characters
My $ qqwry = IP: qqwry: decoded-> New ('qqwry. dat ', 'gbk ');
Open unuse,'iplist.txt ';
While (<unuse> ){
($ Id, $ IP, $ key) =/(\ D +) \ s + (.*?) \ S + (.*)/;
My $ info = $ qqwry-> query ("$ IP"); # In fact, this line is the key code, haha
Printf "% 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.