美文网首页
太强了!这款开源终端工具可查询 IP 信息 ...

太强了!这款开源终端工具可查询 IP 信息 ...

作者: 奋斗的工程师1 | 来源:发表于2022-08-22 17:25 被阅读0次

最近在3A平台的平台下开通了Linux服务器,学习Linux服务器相关知识。 在 Linux 下,有dignslookuptraceroute等多种非常实用的网络调试工具。

  • dig:是常用的域名查询工具,可以用来测试域名是否正常。

  • nslookup:是常用的域名查询工具,也就是查 DNS 信息时用到的命令,它有两种工作模式,分别为交互模式和非交互模式。

交互模式:用户可以向域名服务器查询各类主机、域名的信息或输出域名中的主机列表。 非交互模式:用户可以针对一个主机或域名仅获取它特定的名称或所需信息。

  • traceroute:是用于追踪数据包在网络上传输时的全部路径。

那么,在这篇文章中,给大家介绍一个可以在终端下查询 IP 地理信息和 CDN 提供商的工具 —— nali

nali中文里的谐音是「哪里」。它最初是基于 C 语言编写的小工具,由于版本功能的缺失,js 版本包问题、支持的平台有限。

后来基于 GoLang 重写了这款工具,在原有功能的基础之上增加了对 IPv6 的支持,并且增加了 Geoip2 数据库。

1. nali 的特征

  • 支持多种数据库

  • 纯真 IPv4 离线数据库

  • ZX IPv6 离线数据库

  • Geoip2 城市数据库 (可选)

  • IPIP 数据库 (可选)

  • ip2region 数据库 (可选)

  • CDN 服务提供商查询

  • 支持管道处理

  • 支持交互式查询

  • 支持 IPv4 和 IPv6

  • 支持多语言

  • 查询完全离线

  • 全平台支持

  • 支持彩色输出

2. nali 的安装

通过源码安装 nali,需预先安装 Go >= 1.18 的版本。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n50" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># go install github.com/zu1k/nali</pre>

下载预编译的可执行程序进行安装 nali,可直接通过 nali 项目中的 Release 页面选择适合目前的系统及硬件架构的版本进行下载,解压后直接运行即可。

我这以 CentOS 为例,直接下载的安装包,进行解压编译并更新 nali。

--no-check-certificate参数以不安全的方式连接进行下载。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n54" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># wget http://www.dwhd.org/wp-content/uploads/2015/08/nali-0.2.tar.gz --no-check-certificate

tar xf nali-0.2.tar.gz

cd nali-0.2

./configure && make && make install && nali-update</pre>

3. nali 的使用

查询某个 IP 的地理信息

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n57" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># nali 9.9.9.9
9.9.9.9[美国 纽约IBM公司]</pre>

除上述查询方式以外,还可以结合使用|管道符进行查询。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n59" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># echo IP:8.8.8.8 | nali
IP:8.8.8.8[美国 加利福尼亚州山景市谷歌公司DNS服务器]</pre>

同时查询多个 IP 地址信息

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n61" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># nali 1.1.1.1 8.8.8.8 9.9.9.9
1.1.1.1[澳大利亚]
8.8.8.8[美国 加利福尼亚州山景市谷歌公司DNS服务器]
9.9.9.9[美国 纽约IBM公司]</pre>

交互式查询多个 IP 地址信息,可执行nali回车后,输入 IP 地址,直到查询完毕,使用exitquitCtrl+C退出交互式查询。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n63" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># nali
219.141.136.10
219.141.136.10[北京市 电信]
180.76.76.76
180.76.76.76[北京市 百度公司]
223.5.5.5
223.5.5.5[中国 万网]
exit </pre>

nalidig命令结合使用

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n65" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># dig github.com +short | nali
20.205.243.166[美国 Computer]</pre>

nalinslookup命令结合使用

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n67" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># nslookup github.com 8.8.8.8 | nali
Server: 8.8.8.8[美国 加利福尼亚州山景市谷歌公司DNS服务器]
Address: 8.8.8.8[美国 加利福尼亚州山景市谷歌公司DNS服务器]#53

Non-authoritative answer:
Name: github.com
Address: 20.205.243.166[美国 Computer]</pre>

查看 CDN 服务提供商,CDN 服务通常使用 CNAME 的域名解析方式,需要与 nslookup 或 dig 结合使用。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n69" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># nslookup www.newduba.cn | nali
Server: 192.168.1.1[局域网 对方和您在同一内部网]
Address: 192.168.1.1[局域网 对方和您在同一内部网]#53

Non-authoritative answer:
www.newduba.cn canonical name = www.newduba.cn.w.kunluncan.com.
Name: www.newduba.cn.w.kunluncan.com
Address: 111.31.66.218[中国 移动]
Name: www.newduba.cn.w.kunluncan.com
Address: 111.31.66.220[中国 移动]
Name: www.newduba.cn.w.kunluncan.com
Address: 111.31.66.225[中国 移动]
Name: www.newduba.cn.w.kunluncan.com
Address: 111.31.66.224[中国 移动]
Name: www.newduba.cn.w.kunluncan.com
Address: 111.31.66.221[中国 移动]
Name: www.newduba.cn.w.kunluncan.com
Address: 111.31.66.223[中国 移动]
Name: www.newduba.cn.w.kunluncan.com
Address: 111.31.66.219[中国 移动]
Name: www.newduba.cn.w.kunluncan.com
Address: 111.31.66.222[中国 移动]</pre>

只查询 CDN 服务提供商

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n71" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># nslookup www.xxx.cn | nali cdn</pre>

CNAME 域名单独使用

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n73" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># nali cdn cdn.xxx.com</pre>

4. nali 的使用技巧

更新数据库

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n76" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># nali update</pre>

自定义 IP 数据库,需设置环境变量NALI_DB_IP4NALI_DB_IP6

目前所支持的变量内容:

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n79" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Geoip2 ['geoip', 'geoip2', 'geo']
Chunzhen ['chunzhen', 'qqip', 'qqwry']
IPIP ['ipip', 'ipipfree', 'ipip.net']
Ip2Resion ['ip2region', 'region', 'i2r']</pre>

若使用第三方的 IP 数据库,需手动下载对应的 IP 数据库。

Windows 平台

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="cmd" cid="n82" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">使用 geoip 数据库

set NALI_DB_IP4=geoip
或者使用 powershell
$env:NALI_DB_IP4="geoip"

使用 ipip 数据库

set NALI_DB_IP6=ipip
或者使用 powershell
$env:NALI_DB_IP6="ipip"</pre>

Linux 平台

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n84" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">使用 geoip 数据库
export NALI_DB_IP4=geoip

使用 ipip 数据库
export NALI_DB_IP4=ipip</pre>

相关文章

网友评论

      本文标题:太强了!这款开源终端工具可查询 IP 信息 ...

      本文链接:https://www.haomeiwen.com/subject/zapggrtx.html