开源可视化网络路由追踪工具之nexttrace
简介
GitHub:https://github.com/sjlleo/nexttrace
在 Linux 环境下,用于网络管理的命令有很多。比如:ifconfig、ifup / ifdown、route、arp、netstat、ping、telnet、wget、nslookup 等等。除此之外,还有 traceroute 用来追踪数据包到目标主机间传输时的全部路径,tracepath 用来追踪显示报文到达目的主机所经过的路由信息。
那么,基于 traceroute 和 tracepath 命令,今天跟大家推荐一款基于 Go 语言、轻量级且开源的可视化路由追踪命令行工具 —— NextTrace。
它基于 nexttrace 命令通过命令行显示类似于 traceroute 清晰的路由信息。当执行完一条追踪的路由信息时,会自动生成 MapTrace URL 也就是一个 HTML,通过浏览器访问该 URL 支持以地图或 3D 视角的方式可视化展示。
安装
1 2 3 4 5 6 7 8 | # Linux 一键安装脚本 bash <(curl -Ls https://raw.githubusercontent.com/sjlleo/nexttrace/main/nt_install.sh) # GHPROXY 镜像(国内使用) bash <(curl -Ls https://ghproxy.com/https://raw.githubusercontent.com/sjlleo/nexttrace/main/nt_install.sh) # macOS brew 安装命令 brew tap xgadget-lab/nexttrace && brew install nexttrace |
Windows 用户请直接前往 Release 下载编译后的二进制 exe 文件。
Release
里面为很多系统以及不同架构提供了编译好的二进制可执行文件,如果没有可以自行编译。- 一些本项目的必要依赖在
Windows
上Golang
底层实现不完全,所以目前NextTrace
在Windows
平台出于实验性支持阶段。
使用
NextTrace 默认使用
ICMP协议发起
TraceRoute请求,该协议同时支持
IPv4和
IPv6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # IPv4 ICMP Trace nexttrace 1.0.0.1 # URL nexttrace http://example.com:8080/index.html?q=1 # 表格打印,使用 --table / -t 参数,将实时显示结果 nexttrace --table 1.0.0.1 # IPv6 ICMP Trace nexttrace 2606:4700:4700::1111 # 禁用路径可视化 使用 --map / -M 参数 nexttrace koreacentral.blob.core.windows.net # MapTrace URL: https://api.leo.moe/tracemap/html/c14e439e-3250-5310-8965-42a1e3545266.html |
PS: 路由可视化的绘制模块由 @tsosunchia 同学编写,具体代码可在 tsosunchia/traceMap 查看
需要注意的是,在 LeoMoeAPI 2.0 中,由于新增了了地理位置数据,我们已经弃用 traceMap 插件中 OpenStreetMap API 的在线查询的部分,并且使用自己数据库内的位置信息。
路由可视化功能因为需要每个 Hop 的地理位置坐标,而第三方 API 通常不提供此类信息,所以此功能目前只支持搭配 LeoMoeAPI 使用。
NextTrace
现已经支持快速测试,有一次性测试回程路由需求的朋友可以使用
1 2 3 4 5 | # 北上广(电信+联通+移动+教育网)IPv4 / IPv6 ICMP 快速测试 nexttrace --fast-trace # 也可以使用 TCP SYN 而非 ICMP 进行测试 nexttrace --fast-trace --tcp |
NextTrace
已支持指定网卡进行路由跟踪
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # 请注意 Lite 版本此参数不能和快速测试联用,如有需要请使用 enhanced 版本 # 使用 eth0 网卡 nexttrace --dev eth0 2606:4700:4700::1111 # 使用 eth0 网卡IP # 网卡 IP 可以使用 ip a 或者 ifconfig 获取 # 使用网卡IP进行路由跟踪时需要注意跟踪的IP类型应该和网卡IP类型一致(如都为 IPv4) nexttrace --source 204.98.134.56 9.9.9.9 NextTrace` 也可以使用`TCP`和`UDP`协议发起`Traceroute`请求,不过目前`UDP`只支持`IPv4 # TCP SYN Trace nexttrace --tcp www.bing.com # 可以自行指定端口[此处为443],默认80端口 nexttrace --tcp --port 443 2001:4860:4860::8888 # UDP Trace nexttrace --udp 1.0.0.1 # 可以自行指定端口[此处为5353],默认53端口 nexttrace --udp --port 5353 1.0.0.1 |
NextTrace
也同样支持一些进阶功能,如 TTL 控制、并发数控制、模式切换等
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # 每一跳发送2个探测包 nexttrace --queries 2 www.hkix.net # 无并发,每次只发送一个探测包 nexttrace --parallel-requests 1 www.hkix.net # 从TTL为5开始发送探测包,直到TTL为10结束 nexttrace --first 5 --max-hops 10 www.decix.net # 关闭IP反向解析功能 nexttrace --no-rdns www.bbix.net # 特色功能:打印Route-Path图 # Route-Path图示例: # AS6453 塔塔通信「Singapore『Singapore』」 # ╭╯ # ╰AS9299 Philippine Long Distance Telephone Co.「Philippines『Metro Manila』」 # ╭╯ # ╰AS36776 Five9 Inc.「Philippines『Metro Manila』」 # ╭╯ # ╰AS37963 阿里云「ALIDNS.COM『ALIDNS.COM』」 nexttrace --route-path www.time.com.my |
NextTrace
支持用户自主选择 IP 数据库(目前支持:LeoMoeAPI
, IP.SB
, IPInfo
, IPInsight
, IPAPI.com
, Ip2region
, IPInfoLocal
, CHUNZHEN
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # 可以自行指定IP数据库[此处为IP-API.com],不指定则默认为LeoMoeAPI nexttrace --data-provider ip-api.com ## 特别的: 其中 ipinfo 和 IPInsight API 对于免费版查询有频率限制,可从这些服务商自行购买服务以解除限制,如有需要可以 clone 本项目添加其提供的 token 自行编译 ## TOKEN填写路径:ipgeo/tokens.go ## 特别的: 对于离线库 IPInfoLocal,请自行下载并命名为 ipinfoLocal.mmdb (可以从这里下载:https://ipinfo.io/signup?ref=free-database-downloads) ## 对于离线库 Ip2region 可NextTrace自动下载,也可自行下载并命名为 ip2region.db ## 另外:由于IP.SB被滥用比较严重,会经常出现无法查询的问题,请知悉。 ## IP-API.com限制调用较为严格,如有查询不到的情况,请几分钟后再试。 # 纯真IP数据库默认使用 http://127.0.0.1:2060 作为查询接口,如需自定义请使用环境变量 export NEXTTRACE_CHUNZHENURL=http://127.0.0.1:2060 ## 可使用 https://github.com/freshcn/qqwry 自行搭建纯真IP数据库服务 # 也可以通过设置环境变量来指定默认IP数据库 export NEXTTRACE_DATAPROVIDER=ipinfo |
NextTrace
支持使用混合参数和简略参数
1 2 3 4 5 6 7 | Example: nexttrace --data-provider ip-api.com --max-hops 20 --tcp --port 443 --queries 5 --no-rdns 1.1.1.1 nexttrace -tcp --queries 2 --parallel-requests 1 --table --route-path 2001:4860:4860::8888 Equivalent to: nexttrace -d ip-api.com -m 20 -T -p 443 -q 5 -n 1.1.1.1 nexttrace -T -q 2 --parallel-requests 1 -t -R 2001:4860:4860::8888 |
全部用法详见 Usage 菜单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | Usage: nexttrace [-h|--help] [-T|--tcp] [-U|--udp] [-F|--fast-trace] [-p|--port <integer>] [-q|--queries <integer>] [--parallel-requests <integer>] [-m|--max-hops <integer>] [-d|--data-provider (Ip2region|ip2region|IP.SB|ip.sb|IPInfo|ipinfo|IPInsight|ipinsight|IPAPI.com|ip-api.com|IPInfoLocal|ipinfolocal|chunzhen)] [-n|--no-rdns] [-a|--always-rdns] [-P|--route-path] [-r|--report] [--dn42] [-o|--output] [-t|--table] [-c|--classic] [-f|--first <integer>] [-M|--map] [-v|--version] [-s|--source "<value>"] [-D|--dev "<value>"] [-R|--route] [-z|--send-time <integer>] [-i|--ttl-time <integer>] [_positionalArg_nexttrace_25 "<value>"] [--dot-server (dnssb|aliyun|dnspod|google|cloudflare)] [-g|--language (en|cn)] Arguments: -h --help Print help information -T --tcp Use TCP SYN for tracerouting (default port is 80) -U --udp Use UDP SYN for tracerouting (default port is 53) -F --fast-trace One-Key Fast Trace to China ISPs -p --port Set the destination port to use. It is either initial udp port value for "default"method (incremented by each probe, default is 33434), or initial seq for "icmp" (incremented as well, default from 1), or some constantdestination port for other methods (with default of 80 for "tcp", 53 for "udp", etc.) -q --queries Set the number of probes per each hop. Default: 3 --parallel-requests Set ParallelRequests number. It should be 1 when there is a multi-routing. Default: 18 -m --max-hops Set the max number of hops (max TTL to be reached). Default: 30 -d --data-provider Choose IP Geograph Data Provider [IP.SB, IPInfo, IPInsight, IP-API.com, Ip2region, IPInfoLocal, CHUNZHEN]. Default: LeoMoeAPI -n --no-rdns Do not resolve IP addresses to their domain names -a --always-rdns Always resolve IP addresses to their domain names -P --route-path Print traceroute hop path by ASN and location -r --report output using report mode --dn42 DN42 Mode -o --output Write trace result to file (RealTimePrinter ONLY) -t --table Output trace results as table -c --classic Classic Output trace results like BestTrace -f --first Start from the first_ttl hop (instead from 1). Default: 1 -M --map Disable Print Trace Map -v --version Print version info and exit -s --source Use source src_addr for outgoing packets -D --dev Use the following Network Devices as the source address in outgoing packets -R --route Show Routing Table [Provided By BGP.Tools] -z --send-time Set the time interval for sending every packet. Useful when some routers use rate-limit for ICMP messages. Default: 100 -i --ttl-time Set the time interval for sending packets groups by TTL. Useful when some routers use rate-limit for ICMP messages. Default: 500 --_positionalArg_nexttrace_25 IP Address or domain name --dot-server Use DoT Server for DNS Parse [dnssb, aliyun, dnspod, google, cloudflare] -g --language Choose the language for displaying [en, cn]. Default: cn |
IP 数据以及精准度说明
NextTrace 有多个数据源可以选择,目前默认使用的 LeoMoeAPI 为我们项目维护的数据源。
LeoMoeAPI 早期数据主要来自 IPInsight、IPInfo,随着项目发展,越来越多的志愿者参与进了这个项目。目前 LeoMoeAPI 有近一半的数据是社区提供的,而另外一半主要来自于包含 IPInfo、IPData、BigDataCloud、IPGeoLocation 在内的多个第三方数据。
LeoMoeAPI 的骨干网数据有近 70% 是社区自发反馈又或者是项目组成员校准的,这给本项目的路由跟踪基础功能带来了一定的保证,但是全球骨干网的体量庞大,我们并无能力如 IPIP 等商业公司拥有海量监测节点,这使得 LeoMoeAPI 的数据精准度无法和形如 BestTrace(IPIP)相提并论。
LeoMoeAPI 已经尽力校准了比较常见的骨干网路由,这部分在测试的时候经常会命中,但是如果遇到封闭型 ISP 的路由,大概率可以遇到错误,此类数据不仅是我们,哪怕 IPInsight、IPInfo 也无法正确定位,目前只有 IPIP 能够标记正确,如对此类数据的精确性有着非常高的要求,请务必使用 BestTrace 作为首选。
我们不保证我们的数据一定会及时更新,也不保证数据的精确性,我们希望您在发现数据错误的时候可以前往 issue 页面提交错误报告,谢谢。
当您使用 LeoMoeAPI 即视为您已经完全了解 NextTrace LeoMoeAPI 的数据精确性,并且同意如果您引用 LeoMoeAPI 其中的数据从而引发的一切问题,均由您自己承担。
DN42 模式使用说明
使用这个模式需要您配置 2 个文件,分别是 geofeed.csv 以及 ptr.csv
当您初次运行 DN42 模式,NT 会为您生成 nt_config.yaml 文件,您可以自定义 2 个文件的存放位置,默认应该存放在 NT 的运行目录下
GeoFeed
对于 geofeed.csv 来说,格式如下:
1 | IP_CDIR,LtdCode,ISO3166-2,CityName,ASN,IPWhois |
比如,您可以这么写:
1 | 58.215.96.0/20,CN,CN-JS,Wuxi,23650,CHINANET-JS |
如果您有一个大段作为骨干网使用,您也可以不写地理位置信息,如下:
1 | 202.97.0.0/16,,,4134,CHINANET-BACKBONE |
PTR
对于 ptr.csv 来说,格式如下:
1 | IATA_CODE,LtdCode,RegionName,CityName |
比如对于美国洛杉矶,您可以这么写