简述:在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 : US, N/A, N/A, N/A, 38.000000, -97.000000, , 0 $ geoiplookup 163.177.65.160 -f GeoLiteCity.dat
GeoIP City Edition, Rev : CN, , Guangzhou, N/A, 23.116699, 113.250000, , 0 $ geoiplookup 125.39.240.113 -f GeoLiteCity.dat
GeoIP City Edition, Rev : CN, , Tianjin, N/A, 39.142200, 117.176697, ,  

对应字段:

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

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

查询当前数据库版本:

$ geoiplookup 125.39.240.113 -v
GeoIP Country Edition: GEO-106FREE Build Copyright (c) MaxMind Inc All Rights Reserved
GeoIP ASNum Edition: GEO- Build Copyright (c) MaxMind Inc All Rights Reserved
GeoIP Country V6 Edition: GEO-106FREE Build Copyright (c) MaxMind Inc All Rights Reserved
GeoIP Large Country Edition: GEO-106FREE Build Copyright (c) MaxMind Inc All Rights Reserved
GeoIP Large Country V6 Edition: GEO-106FREE Build Copyright (c) MaxMind Inc All Rights Reserved
GeoIP ASNum V6 Edition: GEO- Build Copyright (c) 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 ::
ipnum:
range_by_num: -
network num: - ::
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 ::
ipnum:
range_by_num: -
network num: - ::

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

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

查看信息来源

[Ubuntu] geoip-bin 程序包 - 查询 IP 归属地的更多相关文章

  1. Linux shell查询ip归属地

    起因 有的时候写脚本需要能够在脚本中获取到ip的归属地,比如分析登录日志列出攻击者的相关信息等. 可以使用whois来查询ip的详细信息,但是whois并不是每台机器预装的,而且我想看中文的结果,所以 ...

  2. 任何快速查询IP归属地

    最近公司项目需要做一个IP归属地查询的功能,想着如果用现成的API就可以大大提高开发效率,所以在网上的API商店搜索了一番,发现了 APISpace,它里面的IP归属地API非常符合我的开发需求.   ...

  3. 利用纯真ip地址库 查询 ip所属地

    1. 首先下周数据源,选择是纯真数据库:http://www.cz88.net/ 2. 安装后,打开软件,将数据导出为txt格式. 3. 处理数据,参照网上的文章(http://www.jb51.ne ...

  4. python 通过线上API查询ip归属地

    API为国外API,频率限制1分钟45个ip 脚本如下 1 #!/usr/bin/env python3 2 #-*-coding:utf-8-*- 3 4 import requests,re,js ...

  5. jquery 查询IP归属地

    <script src="http://c.csdnimg.cn/public/common/libs/jquery/jquery-1.9.1.min.js" type=&q ...

  6. python 利用cip.cc查询IP归属地

    def ipinfocip(ip): # 获得 输入框中的信息 url = "http://www.cip.cc/%s" % ip # 模拟浏览器请求网络 headers={'Us ...

  7. python 利用淘宝IP库 查询IP归属地

    #coding:utf-8 from django.test import TestCase import json import urllib ip = "114.114.114.114& ...

  8. 根据ip查询ip归属地

    http://www.oschina.net/code/snippet_944819_33978 http://www.jb51.net/article/54287.htm public String ...

  9. 在64位Ubuntu系统上安装32位程序包

    在64位Ubuntu系统上安装32位的程序包 $sudo apt-get install package_name:i386 例如: $sudo apt-get install openjdk-7-j ...

随机推荐

  1. 【转】C#多线程环境下调用 HttpWebRequest 并发连接限制

    .net 的 HttpWebRequest 或者 WebClient 在多线程情况下存在并发连接限制,这个限制在桌面操作系统如 windows xp , windows  7 下默认是2,在服务器操作 ...

  2. Spring加载静态资源的方式

    解决方法1:在web.xml里添加如下的配置 <servlet-mapping> <servlet-name>default</servlet-name> < ...

  3. 使用jenkins配置.net mvc网站进行持续集成

    最近好久没有更新文章了,因为好久没有写代码了,以至于我不知道同大家分享些什么,刚好,今天突然叫我学习下jenkins每日构建,我就把今天的学习笔记记录下来,这其中很多东西都是公司同事之前调研总结的,我 ...

  4. application.properties详解 --springBoot配置文件

    本文转载:http://blog.csdn.net/lpfsuperman/article/details/78287265###; # spring boot application.propert ...

  5. fence-agents kvm 实验

    1, Method of installing fence-agents on linux: $ git clone https://github.com/ClusterLabs/fence-agen ...

  6. php 多页面间共享变量

    1. 保存session的页面session1.php <? echo "hi, let's try session<br/>"; session_start() ...

  7. 限定某个目录禁止解析php 限制user_agent php相关配置

  8. 114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果)

    关键操作: 效果如下: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UITableViewCo ...

  9. 2013——M笔试南京——程序

    迄今只参加了M南京笔试,可惜自己不是计算机出身,还有好多东西得学啊…… M的最后一题是编程: 输入:单链表L0.L1.L2……Ln-1.Ln,将链表变为:L0.Ln.L1.Ln-1.L2…… 算法: ...

  10. Visual Studio快捷键大全

    快捷键的使用可以简化大家的操作,在一定程度上提高工作的效率,下文中将为大家介绍一些VS中经常用到的快捷键,希望对大家有用. 方法/步骤   关于解决方案和项目   用于快速跳转   用于代码的文本编辑 ...