基於OpenResty ,MaxMind GeoIP數據庫和從bgp.he.net生成的ASN數據庫,因為沒有經緯度的需求所以沒有顯示。下文有源代碼的鏈接,如果需要可以自行修改加上經緯度或者將輸出變為JSON等。

這裡有chrome插件

使用方法

查詢當前IPv4地址

$ curl http://cidr.me/ip
x.x.x.x

查詢當前IPv6地址

$ curl http://ipv6.cidr.me/ip
x.x.x.x

查詢當前IP的PTR記錄(反向DNS),地理位置和ASN

$ curl http://cidr.me/
x.x.x.x
Country, City
ASN number

查詢當前IP的PTR記錄

$ curl http://cidr.me/rdns
x-x-x-x.com

查詢指定IP的地理位置

$ curl http://cidr.me/74.125.203.199
74.125.203.199 th-in-f199.1e100.net
United States, California, Mountain View
AS15169 Google Inc.

查詢域名的地理位置

$ curl http://cidr.me/www.google.com.hk
172.217.3.195 sea15s12-in-f3.1e100.net
United States, California, Mountain View
AS15169 Google LLC

2607:f8b0:400a:809::2003 sea15s12-in-x03.1e100.net
United States
AS15169 Google LLC

查詢域名的IP

$ curl http://cidr.me/www.google.com.hk/ip
74.125.203.199
2607:f8b0:400a:809::2003

查詢域名的IP和CNAME(如果存在)

$ curl http://cidr.me/www.youtube.com/dns
youtube-ui.l.google.com 172.217.3.174
172.217.3.206
216.58.193.78
216.58.217.46
2607:f8b0:400a:808::200e

源代碼

在這裡https://gist.github.com/fffonion/44e5fb59e2a8f0efba5c1965c6043584

需要ngx_http_geoip_module, echo-nginx-module, lua-nginx-module,安裝libgeoip,並將maxmind的舊版geoip數據庫放在/usr/share/GeoIP

通過bgp.he.net生成ASN數據庫

This service is based on OpenResty, MaxMind GeoIP database and ASN database generated by bgp.he.net. There’s no lat/lng since I don’t need it. Source code is attached below. You can modify it to display lat/lng or output JSON.

Usage

Query current IPv4 address

$ curl http://cidr.me/ip
x.x.x.x

Query current IPv6 address

$ curl http://ipv6.cidr.me/ip
x.x.x.x

Query current IP PTR (reverse DNS), geo location and ASN

$ curl http://cidr.me/
x.x.x.x
Country, City
ASN number

Query current IP PTR (reverse DNS)

$ curl http://cidr.me/rdns
x-x-x-x.com

Query given IP geo location

$ curl http://cidr.me/74.125.203.199
74.125.203.199
United States, California, Mountain View
AS15169 Google Inc.

Query given domain name geo location

$ curl http://cidr.me/www.google.com.hk
74.125.203.199
United States, California, Mountain View
AS15169 Google Inc.

Query given domain name IP

$ curl http://cidr.me/www.google.com.hk/ip
74.125.203.199

Query given domain name IP and CNAME (if exists)

$curl http://cidr.me/www.youtube.com/dns
youtube-ui.l.google.com 172.217.3.174
172.217.3.206
216.58.193.78
216.58.217.46
2607:f8b0:400a:808::200e

Installation

Source code can be viewed here: https://gist.github.com/fffonion/44e5fb59e2a8f0efba5c1965c6043584

nginx with ngx_http_geoip_module, echo-nginx-module, lua-nginx-module is required; libgeoip needs to be installed and geoip database should be placed under /usr/share/GeoIP.

Generate ASN database from bgp.he.net