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