Windows 操作系统使用 Tcping 命令检查目标主机端口是否开放

检查目标主机端口是否开放的方法已经很多了,网络上也有第三方网页版的检查工具,这篇文章给大家介绍一个实用小工具 Tcping 。

一、下载安装 Tcping 命令

Tcping 非 Windows 自带命令,我们需要下载 Tcping 可执行文件,然后将该文件 copy 到  C:\WINDOWS\system32 目录。

下载地址:https://download.elifulkerson.com/files/tcping/0.39/tcping.exe

二、Tcping 命令用法及参数介绍

用法:
    tcping [-tdsvf46] [-i interval] [-n times] [-w interval] [-b n] [-r times][-j depth] [--tee filename] [-f] destination [port]
    
选项/参数:
    -4                   优先使用 IPv4
    -6                   优先使用 IPv6
    -t                   连续 ping , 使用 control+c 结束
    -n count             发送 count 个 ping 后停止。默认为 4。
    -i interval          在每次 ping 之间等待 interval 秒。默认为 1。可以使用小数。
    -w interval          等待 interval 秒收到回复。默认为 2。允许使用小数。
    -d                   在每一行输出中包含日期和时间。
    -f                   除了连接之外,还强制发送至少一个字节。
    -g count             在 count 次 ping 失败后放弃。
    -b type              启用可听见的蜂鸣声。
                           "-b 1" 会在关机时蜂鸣。如果主机是开着的,但现在没开,就蜂鸣。
                           "-b 2" 会在开机时蜂鸣。如果主机是关着的,但现在开了,就蜂鸣。
                           "-b 3" 会在变化时蜂鸣。如果主机原来是一种状态,但现在变成了另一种状态,就蜂鸣。
                           "-b 4" 会一直蜂鸣。
    -c                   只在状态改变时显示输出。
    -r count             每 count 次 ping,我们将为主机执行新的 DNS 查找,以防其发生改变。
    -s                   成功后立即退出。
    -v                   显示版本信息。
    -j                   计算抖动。抖动定义为上一次响应时间与历史平均值之差。
    -js depth            计算抖动,与 -j 类似,但带有可选的 depth 参数。如果指定了 depth,tcping 将使用前面的 depth 值计算滚动平均值。
    --tee _filename_     将输出复制到指定的 filename 。Windows 仍然不能依赖于具有有用的命令行环境。别嘲笑我,*nix 的家伙们。
    --append             使用 --tee 时,将追加而不是覆盖输出文件。
    --file               将 "destination" 选项视为文件名。该文件成为目标的来源,按行循环。某些选项在此模式下不起作用,并且不会保留统计信息。
    destination          DNS 名称、IP 地址或(在 "http" 模式下)URL。
                         在 "http" 模式下不要指定协议("http://")。也不要使用 ":port" 语法指定服务器端口。
                         例如:"tcping http://www.elifulkerson.com:8080/index.html" 会失败
                         请使用这种样式:"tcping www.elifulkerson.com/index.html 8080"。
    port                 TCP 端口,1-65535。如果未指定,默认为 80。
    --header             包含命令行参数和时间戳的标题。如果使用 --tee,则包含标题。
            
HTTP 模式选项:
 
    -h      使用 "http" 模式。在 http 模式下,我们将尝试获取指定的文档,并返回包括文档大小、http 响应代码、kbit/s 等附加值。
    -u      在 "http" 模式下,在每行输出中包含目标 URL。
    --post  在 http 模式下使用 POST 而不是 GET。
    --head  在 http 模式下使用 HEAD 而不是 GET。
    --get   为了保持一致,使用缩写调用 "http" 模式。
    --proxy-server _proxyserver_
            使用代理服务器。
    --proxy-port _port_
            指定代理服务器的 TCP 端口。默认为 3128。
    --proxy-credentials username:password
            指定发送为 'Proxy-Authorization: Basic' 标头的 username:password。
返回值:
    如果所有 ping 均成功,tcping 返回 0;如果没有 ping 成功,则返回 1;如果混合结果,则返回 2。

三、示例

1、No response 表示本地到远程主机的检测端口连接失败。

C:\>tcping hicairo.com 22
Probing 2606:4700:3033::6815:2886:22/tcp - No response - time=2012.589ms
Probing 2606:4700:3033::6815:2886:22/tcp - No response - time=2004.094ms
Probing 2606:4700:3033::6815:2886:22/tcp - No response - time=2014.238ms
Probing 2606:4700:3033::6815:2886:22/tcp - No response - time=2009.873ms
Ping statistics for 2606:4700:3033::6815:2886:22
     4 probes sent.
     0 successful, 4 failed.  (100.00% fail)
Was unable to connect, cannot provide trip statistics.

2、默认检测本地到远程主机的80端口是否可以正常通讯。

C:\>tcping hicairo.com
Probing 2606:4700:3033::6815:2886:80/tcp - Port is open - time=173.642ms
Probing 2606:4700:3033::6815:2886:80/tcp - Port is open - time=183.289ms
Probing 2606:4700:3033::6815:2886:80/tcp - Port is open - time=178.169ms
Probing 2606:4700:3033::6815:2886:80/tcp - Port is open - time=172.620ms
Ping statistics for 2606:4700:3033::6815:2886:80
     4 probes sent.
     4 successful, 0 failed.  (0.00% fail)
Approximate trip times in milli-seconds:
     Minimum = 172.620ms, Maximum = 183.289ms, Average = 176.930ms

本文出处:HiFeng'Blog
本文链接:
https://www.hicairo.com/post/58.html
版权声明:本博客所有文章除特别声明外,均采用CC BY-NC-SA许可协议。转载请注明出处!