如果本机所处的网络中的路由器、网关等设备中有配置透明代理(Shadowsocks 的 ss-redir 等),我们可以使用 tcptraceroute 来测试我们与目标IP/端口间的连接是否会经过该透明代理。

Windows

安装 tcptraceroute

  1. 下载安装 WinPcap
  2. 下载解压 tracetcp

测试连接

首先以管理员身份运行 cmd.exe 或 powershell,随后切换到 tracetcp.exe 所在目录。tracetcp.exe 用法如下:

tracetcp IP|hostname[:port]

如果连接没有经过透明代理,则 tracetcp 命令会需要很久才能完成,且会在结果中列出多跳:

PS C:\bin> tracetcp 114.114.114.114:53

Tracing route to 114.114.114.114 [public1.114dns.com] on port 53
Over a maximum of 30 hops.
1       3 ms    2 ms    2 ms    10.99.28.1      [OpenWrt.lan]
2       2 ms    1 ms    2 ms    192.168.1.1     [SMBSHARE]
3       5 ms    3 ms    4 ms    100.68.192.1
4       *       *       *       Request timed out.
5       5 ms    6 ms    8 ms    139.226.210.77
6       21 ms   20 ms   21 ms   219.158.106.10
7       *       *       *       Request timed out.
8       *       *       *       Request timed out.
9       *       *       *       Request timed out.
10      *       *       *       Request timed out.
11      *       *       *       Request timed out.
12      *       *       *       Request timed out.
13      *       *       *       Request timed out.
14      *       *       *       Request timed out.
15      *       *       *       Request timed out.
16      *       *       *       Request timed out.
17      Destination Reached in 19 ms. Connection established to 114.114.114.114

如果连接经过了透明代理,则 tracetcp 命令仅需几秒就能完成,且返回的结果只会包含1跳:

PS C:\bin> tracetcp 1.1.1.1
Tracing route to 1.1.1.1 [one.one.one.one] on port 80
Over a maximum of 30 hops.
1       Destination Reached in 2 ms. Connection established to 1.1.1.1
Trace Complete.

Linux

安装 tcptraceroute

Ubuntu 19.10+, Debian 10+:

sudo apt install tcptraceroute

Arch Linux:

sudo yay -S tcptraceroute

测试连接

用法如下,其中端口 port 默认80。

sudo tcptraceroute IP/Hostname port

如果连接没有经过透明代理,则 tcptraceroute 命令会需要很久才能完成,且会在结果中列出多跳:

$ sudo tcptraceroute 1.1.1.1
Selected device enp0s31f6, address 10.99.28.99, port 57631 for outgoing packets
Tracing the path to 1.1.1.1 on TCP port 80 (http), 30 hops max
 1  10.99.28.1  0.302 ms  0.224 ms  0.218 ms
 2  192.168.1.1  0.664 ms  0.631 ms  0.591 ms
 3  100.68.192.1  3.166 ms  10.801 ms  5.540 ms
 4  * * *
 5  * * *
 6  219.158.113.114  11.876 ms  6.327 ms  11.776 ms
 7  219.158.113.137  11.188 ms  6.303 ms  11.537 ms
 8  219.158.116.238  200.530 ms  203.248 ms  185.336 ms
 9  * * *
10  * * *
11  1.1.1.1 [open]  181.990 ms  186.445 ms  187.835 ms

如果连接经过了透明代理,则 tcptraceroute 命令仅需几秒就能完成,且返回的结果只会包含1跳:

$ sudo tcptraceroute 1.1.1.1
Selected device enp0s31f6, address 10.99.28.99, port 44889 for outgoing packets
Tracing the path to 1.1.1.1 on TCP port 80 (http), 30 hops max
 1  one.one.one.one (1.1.1.1) [open]  0.326 ms  0.280 ms  0.285 ms