Nali CLI —— 不離開終端也能查看 IP 詳細信息

介紹

Nali 取自中文「哪裏」的拼音。Nali 一開始是數年前由 surfchen 用 C 和 Perl 寫成的小工具( C 用於解析純真 IP 數據庫,Perl 用於解析 stdout ),現在已經失傳。因此我用 Node.js 重寫了這一小工具,命名爲 Nali CLI。html

GitHub | NPM | AUR | 官網linux

安裝

對於環境中已經安裝了 Node.js 的,能夠直接經過 NPM 和 Yarn 安裝:git

# NPM
$ npm i nali-cli -g
# Yarn
$ yarn global add nali-cli

Nali CLI 也有預編譯好的供 macOS x64 和 Linux x64 的二進制文件,能夠在 GitHub Repo 中的 bin 目錄中下載。github

同時感謝 imlonghao 爲 Nali CLI 打的 AUR數據庫

首次運行 Nali CLI 時會自動下載所需的 qqwry.dat$HOME/.config/nali-cli/ 目錄下。npm

使用

Nali CLI 支持從傳入的參數中解析 IP:bash

$ nali 11.4.5.14
11.4.5.14 [美國 俄亥俄州哥倫布市 DoD 網絡信息中心]

$ nali Cloudflare 1.0.0.1 1.1.1.1
Cloudflare 1.1.1.1 [美國 APNIC&CloudFlare 公共 DNS 服務器] 1.0.0.1 [美國 APNIC&CloudFlare 公共 DNS 服務器]

$ nali 114.514.191.9 114.5.1.4
114.514.191.8 114.5.1.4 [印度尼西亞]

除此之外,Nali CLI 內置瞭如下幾個經常使用工具:服務器

  • nali-dig
  • nali-nslookup
  • nali-ping
  • nali-tracepath
  • nali-traceroute

上述工具只是 Wrapper,使用時仍然須要安裝原始程序。好比要使用 nali-dignali-nslookup 須要先安裝 Bind (dnsutils)。網絡

$ nali-nslookup nali.skk.moe 1.1.1.1
Server:         1.1.1.1 [美國 APNIC&CloudFlare 公共 DNS 服務器]
Address:        1.1.1.1 [美國 APNIC&CloudFlare 公共 DNS 服務器]#53

Non-authoritative answer:
Name:   nali.skk.moe
Address: 104.18.100.28 [美國 CloudFlare 公司 CDN 節點]
Name:   nali.skk.moe
Address: 104.18.101.28 [美國 CloudFlare 公司 CDN 節點]
Name:   nali.skk.moe
Address: 2606:4700::6812:641c
Name:   nali.skk.moe
Address: 2606:4700::6812:651c

Nali CLI 還支持從外部的 stdin 中解析和查詢 IP 信息,所以像 mtr 這類未被 Nali CLI 包裝的工具也能夠使用:app

# 這裏以 dig 爲例

$ dig nali.skk.moe @1.1.1.1 +short | nali
104.18.100.28 [美國 CloudFlare 公司 CDN 節點]
104.18.101.28 [美國 CloudFlare 公司 CDN 節點]
對於 mtr 等,還能夠自行建立 nali-mtr 文件並添加到 PATH 中:
#!/bin/sh

mtr $@ 2>&1 | nali
也能夠直接在 .bashrc.zshrc 中註冊 nali-mtr
nali-mtr() {
  mtr $@ 2>&1 | nali
}

Nali CLI 也支持更新 qqwry.dat

$ nali upadte

Interface

$ nali --help

Usage: nali <command> [options]

Options:
  -v, --version  版本信息
  -h, --help     output usage information

Commands:
  parse          解析 stdin 或參數中的 IP 信息 (默認)
  update         更新 IP 庫
  help [cmd]     display help for [cmd]
$ nali update --help       
Usage: update [options]

更新 IP 庫 (qqwry.dat)

Options:
  -r, --remote  獲取最新 IP 庫版本信息
  -f, --force   強制更新 IP 庫
  -y, --yes     直接更新 IP 庫
  -h, --help    output usage information

Related

Author

Nali CLI © Sukka, Released under the GPL-3.0 License.
Authored and maintained by Sukka with help from contributors (list).

Personal Website · Blog · GitHub @SukkaW · Telegram Channel @SukkaChannel · Twitter @isukkaw · Keybase @sukka

本文原發 Sukka's Blog 現轉載發佈在 SegmentFault ( CSDN 常常在 SegmentFault、V2EX、掘金上爬文章,結尾加個 info 跟蹤用)
相關文章
相關標籤/搜索