2020-07-19 07:59:42 +08:00
< h1 align = "center" >
< br > Nali< br >
< / h1 >
2022-03-03 11:21:29 +08:00
< h4 align = "center" > An offline tool for querying IP geographic information and CDN provider.< / h4 >
2020-07-19 07:59:42 +08:00
< p align = "center" >
< a href = "https://github.com/zu1k/nali/actions" >
2023-01-10 11:04:01 +08:00
< img src = "https://img.shields.io/github/actions/workflow/status/zu1k/nali/go.yml?branch=master&style=flat-square" alt = "Github Actions" >
2020-07-19 07:59:42 +08:00
< / a >
< a href = "https://goreportcard.com/report/github.com/zu1k/nali" >
< img src = "https://goreportcard.com/badge/github.com/zu1k/nali?style=flat-square" >
< / a >
< a href = "https://github.com/zu1k/nali/releases" >
< img src = "https://img.shields.io/github/release/zu1k/nali/all.svg?style=flat-square" >
< / a >
2023-02-26 15:49:57 +08:00
< a href = "https://github.com/zu1k/nali/releases" >
< img src = "https://img.shields.io/github/downloads/zu1k/nali/total?style=flat-square" >
< / a >
2020-07-19 07:59:42 +08:00
< / p >
2022-03-03 11:21:29 +08:00
#### [中文文档](https://github.com/zu1k/nali/blob/master/README.md)
2020-07-19 20:17:14 +08:00
2022-03-03 11:21:29 +08:00
## Feature
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
- Multi database support
- Chunzhen qqip database
- ZX ipv6 database
- Geoip2 city database
- IPIP free database
- ip2region database
2023-01-15 12:08:10 +08:00
- DB-IP database
2022-05-17 11:22:30 +08:00
- IP2Location DB3 LITE database
2023-01-15 12:08:10 +08:00
- CDN provider query
2022-03-03 11:21:29 +08:00
- Pipeline support
- Interactive query
- Both ipv4 and ipv6 supported
- Multilingual support
2023-01-15 12:08:10 +08:00
- Offline query
2022-03-03 11:21:29 +08:00
- Full platform support
- Color print
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
## Install
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
### Install from source
2020-07-19 07:59:42 +08:00
2022-10-24 09:53:42 +08:00
Nali Requires Go >= 1.19. You can build it from source:
2020-07-19 07:59:42 +08:00
```sh
2022-05-09 15:17:11 +08:00
$ go install github.com/zu1k/nali@latest
2020-07-19 07:59:42 +08:00
```
2023-01-15 12:08:10 +08:00
### Install pre-build binary
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
Pre-built binaries are available here: [release ](https://github.com/zu1k/nali/releases )
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
Download the binary compatible with your platform, unpack and copy to the directory in path
2020-07-19 07:59:42 +08:00
2022-06-30 19:08:06 +08:00
### Arch Linux
2023-01-15 12:08:10 +08:00
We have published 3 packages in Aur:
2022-06-30 19:08:06 +08:00
- `nali-go` : release version, compile when installing
- `nali-go-bin` : release version, pre-compiled binary
- `nali-go-git` : the latest master branch version, compile when installing
2022-03-03 11:21:29 +08:00
## Usage
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
### Query a simple IP address
2020-07-19 07:59:42 +08:00
```
$ nali 1.2.3.4
1.2.3.4 [澳大利亚 APNIC Debogon-prefix网络]
```
2022-03-03 11:21:29 +08:00
#### or use `pipe`
2020-07-19 07:59:42 +08:00
```
$ echo IP 6.6.6.6 | nali
IP 6.6.6.6 [美国 亚利桑那州华楚卡堡市美国国防部网络中心]
```
2022-03-03 11:21:29 +08:00
### Query multiple IP addresses
2020-07-19 07:59:42 +08:00
```
$ 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 [越南 越南邮电集团公司]
```
2022-03-03 11:21:29 +08:00
### Interactive query
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
use `exit` or `quit` to quit
2020-07-19 07:59:42 +08:00
```
$ 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
```
2023-01-15 12:08:10 +08:00
### Use with `dig`
2020-07-19 07:59:42 +08:00
```
2022-04-03 17:25:55 +08:00
$ dig nali.zu1k.com +short | nali
2020-07-19 07:59:42 +08:00
104.28.2.115 [美国 CloudFlare公司CDN节点]
104.28.3.115 [美国 CloudFlare公司CDN节点]
172.67.135.48 [美国 CloudFlare节点]
```
2023-01-15 12:08:10 +08:00
### Use with `nslookup`
2020-07-19 07:59:42 +08:00
```
2022-04-03 17:25:55 +08:00
$ nslookup nali.zu1k.com 8.8.8.8 | nali
2020-07-19 07:59:42 +08:00
Server: 8.8.8.8 [美国 加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器]
Address: 8.8.8.8 [美国 加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器]#53
Non-authoritative answer:
2022-04-03 17:25:55 +08:00
Name: nali.zu1k.com
2020-07-19 07:59:42 +08:00
Address: 104.28.3.115 [美国 CloudFlare公司CDN节点]
2022-04-03 17:25:55 +08:00
Name: nali.zu1k.com
2020-07-19 07:59:42 +08:00
Address: 104.28.2.115 [美国 CloudFlare公司CDN节点]
2022-04-03 17:25:55 +08:00
Name: nali.zu1k.com
2020-07-19 07:59:42 +08:00
Address: 172.67.135.48 [美国 CloudFlare节点]
```
2022-03-03 11:21:29 +08:00
### Use with any other program
2020-07-19 07:59:42 +08:00
2023-01-15 12:08:10 +08:00
Because nali can read the contents of the `stdin` pipeline, it can be used with any program.
2020-07-19 07:59:42 +08:00
```
bash abc.sh | nali
```
2023-01-15 12:08:10 +08:00
Nali will insert IP information after IP address.
2020-07-19 07:59:42 +08:00
2023-01-15 12:08:10 +08:00
### IPv6 support
2020-07-19 07:59:42 +08:00
2023-01-15 12:08:10 +08:00
Use like IPv4
2020-07-19 07:59:42 +08:00
```
$ 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. 服务器网段]
```
2022-03-03 11:21:29 +08:00
### Query CDN provider
2020-07-19 07:59:42 +08:00
```
$ 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)]
```
2022-03-03 11:21:29 +08:00
## Interface
2020-07-19 07:59:42 +08:00
2023-12-11 09:40:30 +08:00
After nali runs for the first time, a configuration file `config.yaml` will be generated in the config directory (use `nali info` to extract info), the configuration file defines the database information.
2022-05-09 15:17:11 +08:00
2023-01-15 12:08:10 +08:00
A database is defined as follows:
2022-05-09 15:17:11 +08:00
```yaml
- name: geoip
name-alias:
- geolite
- geolite2
format: mmdb
file: GeoLite2-City.mmdb
languages:
- ALL
types:
- IPv4
- IPv6
```
2022-03-03 11:21:29 +08:00
### Help
2020-07-19 07:59:42 +08:00
```
$ nali --help
Usage:
nali [flags]
nali [command]
Available Commands:
2022-03-03 11:21:29 +08:00
completion generate the autocompletion script for the specified shell
2020-07-19 07:59:42 +08:00
help Help about any command
update update chunzhen ip database
Flags:
2022-03-03 11:21:29 +08:00
--gbk Use GBK decoder
-h, --help help for nali
2020-07-19 07:59:42 +08:00
Use "nali [command] --help" for more information about a command.
```
2022-03-03 11:21:29 +08:00
### Update database
2020-07-19 07:59:42 +08:00
2023-01-15 12:08:10 +08:00
Update all databases if available:
2022-05-09 15:17:11 +08:00
2020-07-19 07:59:42 +08:00
```
$ nali update
2020/07/17 12:53:46 正在下载最新纯真 IP 库...
2020/07/17 12:54:05 已将最新的纯真 IP 库保存到本地 /root/.nali/qqwry.dat
```
2023-01-15 12:08:10 +08:00
Update specified databases:
2022-05-09 15:17:11 +08:00
```
$ nali update --db qqwry,cdn
2020/07/17 12:53:46 正在下载最新纯真 IP 库...
2020/07/17 12:54:05 已将最新的纯真 IP 库保存到本地 /root/.nali/qqwry.dat
```
2023-01-15 12:08:10 +08:00
### Specify database
2020-07-19 07:59:42 +08:00
2023-01-15 12:08:10 +08:00
Users can specify which database to use, set environment variables `NALI_DB_IP4` , `NALI_DB_IP6` or both.
2020-07-19 07:59:42 +08:00
2023-01-15 12:08:10 +08:00
Supported database:
2020-07-19 07:59:42 +08:00
2022-05-09 15:17:11 +08:00
- Geoip2 `['geoip', 'geoip2']`
- Chunzhen `['chunzhen', 'qqwry']`
- IPIP `['ipip']`
2022-07-21 14:11:27 +08:00
- Ip2Region `['ip2region', 'i2r']`
2022-05-17 13:35:48 +08:00
- DBIP `['dbip', 'db-ip']`
2022-05-17 11:22:30 +08:00
- IP2Location `['ip2location']`
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
#### Windows
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
##### Use geoip db
2020-07-21 06:24:46 +08:00
2020-07-19 07:59:42 +08:00
```
2021-08-11 10:02:54 +08:00
set NALI_DB_IP4=geoip
2020-08-17 17:44:07 +08:00
2022-03-03 11:21:29 +08:00
or use powershell
2020-08-17 17:44:07 +08:00
2021-08-11 10:02:54 +08:00
$env:NALI_DB_IP4="geoip"
2020-07-19 07:59:42 +08:00
```
2022-03-03 11:21:29 +08:00
##### Use ipip db
2020-07-21 06:24:46 +08:00
```
2021-08-11 10:02:54 +08:00
set NALI_DB_IP6=ipip
2020-08-17 17:44:07 +08:00
2022-03-03 11:21:29 +08:00
or use powershell
2020-08-17 17:44:07 +08:00
2021-08-11 10:02:54 +08:00
$env:NALI_DB_IP6="ipip"
2020-07-21 06:24:46 +08:00
```
2022-03-03 11:21:29 +08:00
#### Linux
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
##### Use geoip db
2020-07-21 06:24:46 +08:00
2020-07-19 07:59:42 +08:00
```
2021-08-11 10:02:54 +08:00
export NALI_DB_IP4=geoip
2020-07-19 07:59:42 +08:00
```
2022-03-03 11:21:29 +08:00
##### Use ipip db
2020-07-21 06:24:46 +08:00
```
2022-03-03 11:21:29 +08:00
export NALI_DB_IP6=ipip
2021-08-11 10:02:54 +08:00
```
2022-03-03 11:21:29 +08:00
### Multilingual support
2021-08-11 10:02:54 +08:00
2022-03-03 11:21:29 +08:00
Specify the language to be used by modifying the environment variable `NALI_LANG` , when using a non-Chinese language only the GeoIP2 database is supported
2021-08-11 10:02:54 +08:00
2022-03-03 11:21:29 +08:00
The values that can be set for this parameter can be found in the list of supported databases for GeoIP2
2021-08-11 10:02:54 +08:00
```
# NALI_LANG=en nali 1.1.1.1
1.1.1.1 [Australia]
2020-07-21 06:24:46 +08:00
```
2022-10-05 22:16:55 +08:00
### Change directory
2020-07-22 07:30:42 +08:00
2022-10-05 22:16:55 +08:00
Set the environment variable `NALI_HOME` to specify the working directory where the configuration file and database are stored. You can also use absolute paths in the configuration file to specify other database paths.
2020-07-22 07:30:42 +08:00
2022-10-05 22:16:55 +08:00
Set the environment variable `NALI_CONFIG_HOME` to specify the configuration file directory and `NALI_DB_HOME` to specify the database file directory.
If no environment variable is specified, the XDG specification will be used, with the configuration file directory in `$XDG_CONFIG_HOME/nali` and the database file directory in `$XDG_DATA_HOME/nali` .
2020-07-22 07:30:42 +08:00
```
2022-05-09 15:17:11 +08:00
set NALI_HOME=D:\nalidb
2020-07-22 07:30:42 +08:00
or
2022-05-09 15:17:11 +08:00
export NALI_HOME=/home/nali
2020-07-22 07:30:42 +08:00
```
2022-03-03 11:21:29 +08:00
## Thanks
2020-07-19 07:59:42 +08:00
2022-07-21 14:11:27 +08:00
- [纯真QQIP离线数据库 ](http://www.cz88.net )
2020-07-19 07:59:42 +08:00
- [qqwry纯真数据库解析 ](https://github.com/yinheli/qqwry )
- [ZX公网ipv6数据库 ](https://ip.zxinc.org/ipquery/ )
- [Geoip2 city数据库 ](https://www.maxmind.com/en/geoip2-precision-city-service )
- [geoip2-golang解析器 ](https://github.com/oschwald/geoip2-golang )
- [CDN provider数据库 ](https://github.com/SukkaLab/cdn )
2020-07-21 06:24:46 +08:00
- [IPIP数据库 ](https://www.ipip.net/product/ip.html )
- [IPIP数据库解析 ](https://github.com/ipipdotnet/ipdb-go )
2022-02-20 11:33:19 +08:00
- [ip2region数据库 ](https://github.com/lionsoul2014/ip2region )
2022-05-17 11:22:30 +08:00
- [IP2Location DB3 LITE ](https://lite.ip2location.com/database/db3-ip-country-region-city ) *use the IPv6 BIN as it contains both IPv4 & IPv6*
2020-07-19 07:59:42 +08:00
- [Cobra CLI库 ](https://github.com/spf13/cobra )
2022-03-03 11:21:29 +08:00
Thanks to JetBrains for the Open Source License
2021-11-04 21:37:55 +08:00
< a href = "https://www.jetbrains.com/?from=nali" >
< img src = "assets/GoLand.svg" >
< / a >
2022-03-03 11:21:29 +08:00
## Author
2020-07-19 07:59:42 +08:00
2022-03-03 11:21:29 +08:00
**Nali** © [zu1k ](https://github.com/zu1k ), Released under the [MIT ](./LICENSE ) License.< br >