给 mac 安装个更好的 tcping
最近在局域网部署了透明代理/网关,想要测试一下局域网设备的 terminal 是否能正常通过 tcp 无感连接到 Internet,于是安装 tcping
测试。
我的 mac 还是 intel mac,macOS version 还是 10.15.4
。
众所周知 brew 官方源(是官方源这种说法吗?)提供了 tcping
工具,大小也很小。
brew install tcping
使用上面的命令就可以安装,如果有网络问题建议在终端使用代理,比如
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
安装好的 tcping 位于 /usr/local/bin/tcping
但是这货实在是太“简洁”了(usage 如下),不是我们想要的基于 tcp 的 ping 功能,似乎只能检测端口是否有打开。
tcping --help
error: Usage: tcping [-q] [-t timeout_sec] [-u timeout_usec] <host> <port>
下面推荐一个开源项目,给你的 mac 安装个比 brew “自带的”更好的 tcping 工具吧。
paradiseduo/tcping ,喜欢的话可以给原作者一个 star ⭐️️
安装方式如作者所说。如果你事先有安装上面 brew 那个,先卸载之,使用命令 brew uninstall tcping
,然后开始安装
wget https://github.com/paradiseduo/tcping/releases/download/3.5/tcping.zip
unzip tcping.zip
chmod +x tcping
mv tcping /usr/local/bin/
sudo xattr -rd com.apple.quarantine /usr/local/bin/tcping
tcping -c 4 www.baidu.com 80
www.baidu.com:80 has address: 112.80.248.75:80 - Connected - 31.581ms
www.baidu.com:80 has address: 112.80.248.75:80 - Connected - 11.17ms
www.baidu.com:80 has address: 112.80.248.75:80 - Connected - 11.643ms
www.baidu.com:80 has address: 112.80.248.75:80 - Connected - 5.061ms
Ping statistics www.baidu.com:80
4 probes sent.
4 successful, 0 failed.
Approximate trip times:
Minimum = 5.061ms, Maximum = 31.581ms, Average = 14.864ms
tcping -c 4 www.google.com 443
www.google.com:443 has address: 157.240.17.41:443 - Connected - 11.16ms
www.google.com:443 has address: 157.240.17.41:443 - Connected - 4.656ms
www.google.com:443 has address: 157.240.17.41:443 - Connected - 11.117ms
www.google.com:443 has address: 157.240.17.41:443 - Connected - 11.06ms
Ping statistics www.google.com:443
4 probes sent.
4 successful, 0 failed.
Approximate trip times:
Minimum = 4.656ms, Maximum = 11.16ms, Average = 9.498ms
经过测试局域网设备的 terminal 可以无感通过 tcp 连接到 Internet。但是 http_proxy 和 https_proxy 以及 socks5 proxy 需要手动 export
usage
tcping --help
dP oo
88
d8888P .d8888b. 88d888b. dP 88d888b. .d8888b. {Version: 3.5}
88 88 88 88 88 88 88 88 88
88 88. 88. .88 88 88 88 88. .88
dP `88888P 88Y888P dP dP dP `8888P88
88 .88
dP d8888P
tcping is a ping over tcp connection.
Examples:
1. ping over tcp with custom port 10 times
> tcping www.baidu.com 80
2. ping over tcp with custom port 5 times
> tcping -c 5 www.baidu.com 443
USAGE: tcping [--count <count>] [--interval <interval>] <ip> <port>
ARGUMENTS:
<ip> The IP or Domain to tcping.
<port> The port to tcping.
OPTIONS:
-c, --count <count> The number of times to repeat 'tcping'. Default value is 10, Max value is 65535
-i, --interval <interval> The request interval(second). Default value is 1 second
-h, --help Show help information.
3.5 版本增加了选项 -i, --interval <interval> The request interval(second). Default value is 1 second
(新增-i --interval参数,可以设置每次tcping的时间间隔,单位为秒,100毫秒可以传0.1)
至此,舒服了。