[Ubuntu] geoip-bin 程序包 - 查询 IP 归属地

简述:在Linux命令行下查询IP归属地。

 

对Ubuntu/Debian系统,使用APT命令进行安装:

$ sudo apt-get install geoip-bin

 

该包由MaxMind提供,它同时提供了国家、城市和自治系统号(ASN)查询。

自治系统号(ASN)是什么?

ASN - Autonomous System Number:自治系统号。
AS - Autonomous System:自治系统。

自治系统是指在互联网中,有权自主决定本地网络系统采取何种路由协议的小型单位。

这里所称的本地网络系统可以是一个单一局域网,也可以是多个局域网集群,例如一家企业、一所大学。一个自治系统会分配一个全局的唯一的识别号,这个号码称之为自治系统号。

自治系统内部使用内部网关协议进行路由信息的通信,自治系统之间使用边界网关协议进行路由信息的通信。

一个自治系统也可以视为一个或多个网络运营商来运行一个或多个网络协议前缀的网络连接组合,这些运营商往往都具有单独的明确的路由策略。

 

这个包完成安装后,会自动安装两个免费的国家IP数据库,默认安装地址为:/usr/share/GeoIP/GeoIP.dat, /usr/share/GeoIP/GeoIPv6.dat,这个数据库在安装时不一定是最新的,你需要自己手动更新,大概每月更新一次。下载地址为:GeoLite Free Downloadable Databases,提供的下载有国家、城市、ASN三类数据库,可以全部使用以下方法下载到 /usr/share/GeoIP 目录下。

$ cd /usr/share/GeoIP
$ sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz -O GeoIP.dat.gz
$ sudo gzip -d GeoIP.dat.gz

 

查询IP所属国家(第三行 GeoIP ASNum需要下载了GeoIPASNum.dat):

$ geoiplookup 8.8.8.8
GeoIP Country Edition: US, United States
GeoIP ASNum Edition: AS15169 Google Inc.

 

查询IP所属城市(需要下载GeoLiteCity.dat):

$ geoiplookup 8.8.8.8 -f GeoLiteCity.dat
GeoIP City Edition, Rev 1: US, N/A, N/A, N/A, 38.000000, -97.000000, 0, 0

$ geoiplookup 163.177.65.160 -f GeoLiteCity.dat GeoIP City Edition, Rev 1: CN, 30, Guangzhou, N/A, 23.116699, 113.250000, 0, 0

$ geoiplookup 125.39.240.113 -f GeoLiteCity.dat GeoIP City Edition, Rev 1: CN, 28, Tianjin, N/A, 39.142200, 117.176697, 0, 0 

 

对应字段:

GeoIP City Edition, Rev 1: country, region, city, postalCode, latitude, longitude, metroCode, areaCode

GeoIP City Edition, Rev 1: CN, 28, Tianjin, N/A, 39.142200, 117.176697, 0, 0

  

查询当前数据库版本:

$ geoiplookup 125.39.240.113 -v
GeoIP Country Edition: GEO-106FREE 20131105 Build 1 Copyright (c) 2013 MaxMind Inc All Rights Reserved
GeoIP ASNum Edition: GEO-117 20131118 Build 1 Copyright (c) 2013 MaxMind Inc All Rights Reserved
GeoIP Country V6 Edition: GEO-106FREE 20131105 Build 1 Copyright (c) 2013 MaxMind Inc All Rights Reserved
GeoIP Large Country Edition: GEO-106FREE 20131105 Build 1 Copyright (c) 2013 MaxMind Inc All Rights Reserved
GeoIP Large Country V6 Edition: GEO-106FREE 20131105 Build 1 Copyright (c) 2013 MaxMind Inc All Rights Reserved
GeoIP ASNum V6 Edition: GEO-117 20130306 Build 1 Copyright (c) 2013 MaxMind Inc All Rights Reserved

 

查看更多信息:

$ geoiplookup 125.39.240.113 -i
GeoIP Country Edition: CN, China
  ipaddr: 125.39.240.113
  range_by_ip:  125.31.192.0 - 125.47.255.255
  network:      125.32.0.0 - 125.47.255.255 ::12
  ipnum: 2099769457
  range_by_num: 2099232768 - 2100297727
  network num:  2099249152 - 2100297727 ::12
GeoIP ASNum Edition: AS4837 CNCGROUP China169 Backbone
  ipaddr: 125.39.240.113
  range_by_ip:  125.35.128.0 - 125.46.111.255
  network:      125.36.0.0 - 125.39.255.255 ::14
  ipnum: 2099769457
  range_by_num: 2099478528 - 2100195327
  network num:  2099511296 - 2099773439 ::14

 

MaxMind定期测试IP归属地查询准确性,其官网提供了针对不同国家的测试结果

Country    Correctly resolved within forty kilometers    Incorrectly resolved    City is unknown
China                         60%                               31%                    9%

 

查看信息来源

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值