perl批量查询ip归属地的方法代码
时间:2023-08-11 22:53:54
由于业务需要,要查询客户的ip地址,将部分地区的客户过滤出来,开始想到使用ip数据库,发现读取纯真数据库的难度对我来说有些大,而我目前的时间要求比较紧迫,通过在群里询问,感谢黑影子和扶凯的帮忙,推荐了IP::QQWry::Decoded这个模块,该模块是专门用来读取qqwry纯真数据库的,用起来非常简单。
#!/usr/bin/perl
use IP::QQWry::Decoded;
use Encode;
use utf8;
binmode(STDIN, ':encoding(utf8)'); #这三行
binmode(STDOUT, ':encoding(utf8)'); #抄别人的
binmode(STDERR, ':encoding(utf8)'); #用来输出中文,和拿中文查找
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"); #其实关键代码就这一行,哈哈
printf "%s\t%s\t%s\n",$id,$ip,$key if $info=~/地区名/;
}
标签:批量,查询,ip
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Django之PopUp的具体实现方法
2023-03-26 13:04:54
9个个人网站制作诀窍
2007-12-13 11:36:00
详解Python odoo中嵌入html简单的分页功能
2021-05-21 12:24:06
![](https://img.aspxhome.com/file/2023/6/101496_0s.png)
js实现复制功能(多种方法集合)
2024-05-09 10:36:31
利用python在excel里面直接使用sql函数的方法
2023-10-15 00:34:57
![](https://img.aspxhome.com/file/2023/1/81781_0s.jpg)
使用Python编写类UNIX系统的命令行工具的教程
2023-08-24 05:03:02
Mysql 执行一条语句的整个过程详细
2024-01-19 08:53:08
![](https://img.aspxhome.com/file/2023/5/121545_0s.png)
Python使用Dash开发网页应用的方法详解
2022-04-26 03:45:14
![](https://img.aspxhome.com/file/2023/5/99205_0s.gif)
Opencv图像处理之详解掩膜mask
2022-08-12 23:40:44
![](https://img.aspxhome.com/file/2023/9/72219_0s.jpg)
实例演练ASP+XML编程
2007-10-11 13:53:00
python安装whl文件的实战步骤
2022-04-06 19:59:00
![](https://img.aspxhome.com/file/2023/3/118033_0s.png)
Dreamweaver 网页编辑常用表现的实现方法
2010-10-20 20:05:00
使用C#配合ArcGIS Engine进行地理信息系统开发
2023-06-25 16:35:01
![](https://img.aspxhome.com/file/2023/6/61966_0s.jpg)
Python实现账号密码输错三次即锁定功能简单示例
2023-07-22 07:40:21
谷歌历年母亲节Logo一览
2009-05-11 12:17:00
![](https://img.aspxhome.com/file/UploadPic/20095/11/goog_md_aus-19s.jpg)
django的分页器Paginator 从django中导入类
2022-02-07 04:24:29
![](https://img.aspxhome.com/file/2023/9/102809_0s.png)
Python列表去重的几种方法整理
2022-06-18 18:05:17
![](https://img.aspxhome.com/file/2023/8/120468_0s.png)
MySQL学习之基础命令实操总结
2024-01-16 17:27:32
![](https://img.aspxhome.com/file/2023/9/122869_0s.png)
Python中print()函数的用法详情
2021-01-11 21:35:17
![](https://img.aspxhome.com/file/2023/4/101724_0s.png)
Python开发SQLite3数据库相关操作详解【连接,查询,插入,更新,删除,关闭等】
2024-01-21 15:16:21