Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


Windows PowerShell 使用 Test-NetConnection 测试网络连接

PowerShell Windows 大约 2141 字

Test-NetConnection

可简写为TNCtnc

PS C:\> Get-Alias tnc

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           TNC -> Test-NetConnection                          1.0.0.0    NetTCPIP

测试网络

tnc默认使用ping连接internetbeacon.msedge.net

tnc

输出

PS C:\> tnc


ComputerName           : internetbeacon.msedge.net
RemoteAddress          : 13.107.4.52
InterfaceAlias         : WLAN
SourceAddress          : 192.168.1.100
PingSucceeded          : True
PingReplyDetails (RTT) : 42 ms

测试端口

等同于telnet www.baidu.com 443nc -vz www.baidu.com 443等端口测试命令。

Test-NetConnection -ComputerName www.baidu.com -Port 443

输出

PS C:\> Test-NetConnection -ComputerName www.baidu.com -Port 443


ComputerName     : www.baidu.com
RemoteAddress    : 180.101.49.11
RemotePort       : 443
InterfaceAlias   : WLAN
SourceAddress    : 192.168.1.100
TcpTestSucceeded : True

测试本地端口(未开启8080端口)

Test-NetConnection -ComputerName 127.0.0.1 -Port 8080

输出

PS C:\> Test-NetConnection -ComputerName 127.0.0.1 -Port 8080
警告: TCP connect to (127.0.0.1 : 8080) failed


ComputerName           : 127.0.0.1
RemoteAddress          : 127.0.0.1
RemotePort             : 8080
InterfaceAlias         : Loopback Pseudo-Interface 1
SourceAddress          : 127.0.0.1
PingSucceeded          : True
PingReplyDetails (RTT) : 0 ms
TcpTestSucceeded       : False

简写

tnc www.baidu.com -p 443

输出详细信息

tnc www.baidu.com -p 443 -InformationLevel "Detailed"

输出

PS C:\Users\thunk> tnc www.baidu.com -p 443 -InformationLevel "Detailed"


ComputerName            : www.baidu.com
RemoteAddress           : 180.101.49.12
RemotePort              : 443
NameResolutionResults   : 180.101.49.12
                          180.101.49.11
MatchingIPsecRules      :
NetworkIsolationContext : Internet
IsAdmin                 : False
InterfaceAlias          : WLAN
SourceAddress           : 192.168.1.100
NetRoute (NextHop)      : 192.168.1.1
TcpTestSucceeded        : True

更多帮助

Get-Help tnc

或者

man tnc

参考

https://docs.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection

阅读 4564 · 发布于 2022-06-27

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批