6

纯真 IP 数据库 QQWry 解析库 Python 3 版

 3 years ago
source link: https://blog.lilydjwg.me/2014/5/27/qqwry-dat-parser-python-3-version.47207.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

纯真 IP 数据库 QQWry 解析库 Python 3 版

本文来自依云's Blog,转载请注明。

这东西挺好用的,可惜我只寻到一多年以前的 Python 2 版本的,作者是 AutumnCat,不认识。但注释里提到的修改者 bones7456 是鼎鼎大名的骨头兄,现其博客已经长草……

一直以来,我都是通过子进程调用来使用的,因为我写的代码是 Python 3 版,比如这个寻找文本里的 IP 地址并标记的 ipmarkup 脚本。配合 Python 3.2 加入的 functools.lru_cache,效率还不错的样子。但近期有大量 IP 需要查询,才感到每个 IP 都开个子进程的方式实在太慢。遂将其修改为 Python 3 版,并加入了些 Python 后来才流行的 idiom。

脚本还是扔到 winterpy 仓库里了。GPLv2 授权的。

2014年8月2日更新:增加了在线更新的功能,从此不需要 Wine 就能更新数据库啦 :-) 更新方法来自微菜。更新命令如下:

python3 -m QQWry update

发送到 Kindle

Category: python | Tags: python IP地址 | Read Count: 11571

评论 (13)
MaskRay 说: 7 年前

和maxmind.com的GeoIP比怎麼樣?

依云 说: 7 年前

那个不是只精确到国家的么?

MaskRay 说:
7 年前

% geoiplookup 1.2.4.8
GeoIP Country Edition: CN, China
GeoIP City Edition, Rev 1: CN, N/A, N/A, N/A, N/A, 35.000000, 105.000000, 0, 0
GeoIP ISP Edition: IP Address not found
GeoIP Organization Edition: China Network Information Center
GeoIP ASNum Edition: AS24151 China Internet Network Infomation Center
GeoIP Netspeed Edition: Unknown
GeoIP Domain Name Edition: IP Address not found
% geoiplookup 1.2.4.8
GeoIP Country Edition: CN, China
GeoIP City Edition, Rev 1: CN, N/A, N/A, N/A, N/A, 35.000000, 105.000000, 0, 0
GeoIP ISP Edition: IP Address not found
GeoIP Organization Edition: China Network Information Center
GeoIP ASNum Edition: AS24151 China Internet Network Infomation Center
GeoIP Netspeed Edition: Unknown
GeoIP Domain Name Edition: IP Address not found

公開的http ftp列目錄站點能查到
GeoIPASNum.dat GeoIPCity.dat GeoIP.dat GeoIPDomain.dat GeoIPISP.dat GeoIPNetSpeed.dat GeoIPOrg.dat GeoIPv6.dat

依云 说:
7 年前

有些是收费的呢。

CNLIC 说:
7 年前

你那有更新的吗?谢谢

root@do:~# ls -l /usr/share/GeoIP/
total 108176
-rw-r--r-- 1 root root 756904 Jan 7 03:13 GeoIP.dat
-rw-r--r-- 1 root root 3792589 Jan 5 14:06 GeoIPASNum.dat
-rw-r--r-- 1 root root 50585010 Jan 11 19:15 GeoIPCity.dat
-rw-r--r-- 1 root root 4805774 Jan 11 19:16 GeoIPDomain.dat
-rw-r--r-- 1 root root 2912896 Jan 11 19:17 GeoIPISP.dat
-rw-r--r-- 1 root root 7258766 Jan 11 19:17 GeoIPNetSpeedCell.dat
-rw-r--r-- 1 root root 31968222 Jan 11 19:17 GeoIPOrg.dat
-rw-r--r-- 1 root root 8675929 Jan 11 15:15 GeoIPRegion.dat
root@do:~# geoiplookup google.com -v
GeoIP Country Edition: GEO-106FREE 20150106 Build 1 Copyright (c) 2015 MaxMind Inc All Rights Reserved
GeoIP City Edition, Rev 1: GEO-133 20140909 Build 1 Copyright (c) 2014 MaxMind Inc All Rights Reserved
GeoIP Region Edition, Rev 1: GEO-115 20110816 Build 1 Copyright (c) 2011 MaxMind Inc All Rights Reserved
GeoIP ISP Edition: GEO-121 20140902 Build 1 Copyright (c) 2014 MaxMind Inc All Rights Reserved
GeoIP Organization Edition: GEO-111 20131203 Build 1 Copyright (c) 2013 MaxMind Inc All Rights Reserved
GeoIP City Edition, Rev 0: GEO-133 20140909 Build 1 Copyright (c) 2014 MaxMind Inc All Rights Reserved
GeoIP Region Edition, Rev 0: GEO-115 20110816 Build 1 Copyright (c) 2011 MaxMind Inc All Rights Reserved
GeoIP ASNum Edition: GEO-117 20150105 Build 1 Copyright (c) 2015 MaxMind Inc All Rights Reserved
GeoIP Domain Name Edition: GEO-173 20120904 Build 1 Copyright (c) 2012 MaxMind Inc All Rights Reserved
GeoIP Large Country Edition: GEO-106FREE 20150106 Build 1 Copyright (c) 2015 MaxMind Inc All Rights Reserved


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK