
An offline tool for querying IP geographic information and CDN provider. 一个查询IP地理信息和CDN服务提供商的离线终端工具.
Nali 需要预先安装 Go >= 1.26. 安装后可以从源码安装软件:
$ go install github.com/zu1k/nali@latest
可以从Release页面下载预编译好的可执行程序: Release
你需要选择适合你系统和硬件架构的版本下载,解压后可直接运行
我们在 Aur 中发布了 3 个相关的包:
nali-go: Release 版本,安装时编译nali-go-bin: Release 版本,预编译的二进制文件nali-go-git: 最新的 master 分支版本,安装时编译从 Release 页面下载对应架构(amd64、i386、armhf、arm64)的 .deb 包后安装:
$ sudo apt install ./nali_*_amd64.deb
$ nali 1.2.3.4
1.2.3.4 [澳大利亚 APNIC Debogon-prefix网络]
管道$ echo IP 6.6.6.6 | nali
IP 6.6.6.6 [美国 亚利桑那州华楚卡堡市美国国防部网络中心]
$ nali 1.2.3.4 4.3.2.1 123.23.3.0
1.2.3.4 [澳大利亚 APNIC Debogon-prefix网络]
4.3.2.1 [美国 新泽西州纽瓦克市Level3Communications]
123.23.3.0 [越南 越南邮电集团公司]
使用 exit 或 quit 退出查询
$ nali
123.23.23.23
123.23.23.23 [越南 越南邮电集团公司]
1.0.0.1
1.0.0.1 [美国 APNIC&CloudFlare公共DNS服务器]
8.8.8.8
8.8.8.8 [美国 加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器]
quit
dig 命令配合使用需要你系统中已经安装好 dig 程序
$ dig nali.zu1k.com +short | nali
104.28.2.115 [美国 CloudFlare公司CDN节点]
104.28.3.115 [美国 CloudFlare公司CDN节点]
172.67.135.48 [美国 CloudFlare节点]
nslookup 命令配合使用需要你系统中已经安装好 nslookup 程序
$ nslookup nali.zu1k.com 8.8.8.8 | nali
Server: 8.8.8.8 [美国 加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器]
Address: 8.8.8.8 [美国 加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器]#53
Non-authoritative answer:
Name: nali.zu1k.com
Address: 104.28.3.115 [美国 CloudFlare公司CDN节点]
Name: nali.zu1k.com
Address: 104.28.2.115 [美国 CloudFlare公司CDN节点]
Name: nali.zu1k.com
Address: 172.67.135.48 [美国 CloudFlare节点]
因为 nali 支持管道处理,所以可以和任意程序配合使用
bash abc.sh | nali
Nali 将在 IP后面插入IP地理信息,CDN域名后面插入CDN服务提供商信息
和 IPv4 用法完全相同
$ nslookup google.com | nali
Server: 127.0.0.53 [局域网 IP]
Address: 127.0.0.53 [局域网 IP]#53
Non-authoritative answer:
Name: google.com
Address: 216.58.211.110 [美国 Google全球边缘网络]
Name: google.com
Address: 2a00:1450:400e:809::200e [荷兰Amsterdam Google Inc. 服务器网段]
因为 CDN 服务通常使用 CNAME 的域名解析方式,所以推荐与 nslookup 或者 dig 配合使用,在已经知道 CNAME 后可单独使用
$ nslookup www.gov.cn | nali
Server: 127.0.0.53 [局域网 IP]
Address: 127.0.0.53 [局域网 IP]#53
Non-authoritative answer:
www.gov.cn canonical name = www.gov.cn.bsgslb.cn [白山云 CDN].
www.gov.cn.bsgslb.cn [白山云 CDN] canonical name = zgovweb.v.bsgslb.cn [白山云 CDN].
Name: zgovweb.v.bsgslb.cn [白山云 CDN]
Address: 103.104.170.25 [新加坡 ]
Name: zgovweb.v.bsgslb.cn [白山云 CDN]
Address: 2001:428:6402:21b::5 [美国Louisiana州Monroe Qwest Communications Company, LLC (CenturyLink)]
Name: zgovweb.v.bsgslb.cn [白山云 CDN]
Address: 2001:428:6402:21b::6 [美国Louisiana州Monroe Qwest Communications Company, LLC (CenturyLink)]
程序第一次运行后,会在 config 目录生成配置文件 config.yaml (使用 nali info 来查看具体信息),配置文件定义了数据库信息,默认用户无需进行修改
数据库格式默认如下:
- name: geoip
name-alias:
- geolite
- geolite2
format: mmdb
file: GeoLite2-City.mmdb
languages:
- ALL
types:
- IPv4
- IPv6
其中,languages 和 types 表示该数据库支持的语言和查询类型。 如果你需要增加数据库,需小心修改配置文件,如果有任何问题,欢迎提 issue 询问。
旧版本生成的配置文件无需修改:配置文件中找不到的数据库会使用内置的默认定义。
| 数据库 | 名称 / 别名 | 查询类型 | 默认文件 | 自动下载 |
|---|---|---|---|---|
| 纯真 IPv4 | qqwry, chunzhen | IPv4(默认) | qqwry.dat | ✓ |
| ZX IPv6 | zxipv6wry, zxipv6, zx | IPv6(默认) | zxipv6wry.db | ✓ |
| ip2region IPv4 | ip2region, i2r | IPv4 | ip2region.xdb | ✓ |
| ip2region IPv6 | ip2region-ipv6, i2r-ipv6 | IPv6 | ip2region_v6.xdb | ✓ |
| IPinfo Lite | ipinfo | IPv4、IPv6 | ipinfo_lite.mmdb | ✓ |
| GeoIP2 / GeoLite2 City | geoip, geoip2, geolite, geolite2 | IPv4、IPv6 | GeoLite2-City.mmdb | 需手动下载 |
| DB-IP | dbip, db-ip | IPv4、IPv6 | dbip.mmdb | 需手动下载 |
| IPIP | ipip | IPv4、IPv6 | ipipfree.ipdb | 需手动下载 |
| IP2Location DB3 LITE | ip2location | IPv4、IPv6 | IP2LOCATION-LITE-DB3.IPV6.BIN | 需手动下载 |
| CDN | cdn | 域名(默认) | cdn.yml | ✓ |
支持自动下载的数据库在首次使用、本地文件不存在时会自动下载;需手动下载的数据库请将文件放入 nali info 显示的数据目录,或在配置文件中用绝对路径指定 file。
IPinfo Lite 提供免费的国家和 ASN 数据,同时支持 IPv4 和 IPv6,首次使用时自动下载:
$ NALI_DB_IP4=ipinfo NALI_DB_IP6=ipinfo nali 8.8.8.8 2001:4860:4860::8888
8.8.8.8 [United States AS15169 Google LLC]
2001:4860:4860::8888 [United States AS15169 Google LLC]
$ NALI_DB_IP4=ipinfo nali --json 8.8.8.8
{"type":0,"ip":"8.8.8.8","text":"United States AS15169 Google LLC","source":"ipinfo","info":{"network":"8.8.8.0/24","country":"United States","country_code":"US","continent":"North America","continent_code":"NA","asn":"AS15169","as_name":"Google LLC","as_domain":"google.com"}}
长期使用可在配置文件中将 selected.ipv4、selected.ipv6 设为 ipinfo。
文本输出包含国家、ASN 和 AS 名称;JSON 输出包含 network、country、country_code、continent、continent_code、asn、as_name、as_domain。数据库记录未提供 network 字段时,使用命中的 CIDR 网段。名称为数据库中的英文原文。
format 为 mmdb 的数据库会根据元数据自动识别是否为 IPinfo 格式,因此也可以使用登录 IPinfo 后下载的 ipinfo_lite.mmdb。默认下载地址是社区维护的镜像 NetworkCats/IPinfoLite-Download,可以在配置文件中通过 download-urls 改为其他地址:
- name: ipinfo
format: mmdb
file: ipinfo_lite.mmdb
download-urls:
- https://github.com/NetworkCats/IPinfoLite-Download/releases/latest/download/ipinfo_lite.mmdb
languages: [en]
types: [IPv4, IPv6]
IPinfo Lite 数据以 CC BY-SA 4.0 许可发布,公开使用其数据时请注明来源 IPinfo。
ip2region 分为 IPv4(ip2region)和 IPv6(ip2region-ipv6)两个数据库文件,首次使用时自动下载:
$ NALI_DB_IP4=ip2region NALI_DB_IP6=ip2region-ipv6 nali 223.5.5.5 240e::1
223.5.5.5 [中国|浙江省|杭州市|阿里|CN]
240e::1 [中国|北京市|北京市|电信|CN]
旧版本的 ip2region.xdb 文件仍可直接使用;配置文件中失效的旧下载地址会在启动时自动迁移到 ip2region_v4.xdb。
$ nali --help
Usage:
nali [flags]
nali [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
info get the necessary information of nali
update update ip databases and cdn, update nali to latest version if -v
Flags:
--color string Colorize output: auto, always or never (NO_COLOR is honored in auto mode) (default "auto")
--gbk Decode input as GBK (detected automatically on Chinese Windows)
-h, --help help for nali
-j, --json Output in JSON format
-v, --version version for nali
Use "nali [command] --help" for more information about a command.
不带参数时更新纯真、ZX IPv6、ip2region (IPv4) 和 CDN 数据库。体积较大的可选数据库 ip2region-ipv6(约 37 MB)和 ipinfo(约 24 MB)只在被选用(配置文件的 selected 或 NALI_DB_* 环境变量)或本地已存在时才会更新。