PowerShell提供 测试网络连接 等于ping命令的命令或cmdlet。Test NetConnection命令用于打印有关连接和端口的详细信息和诊断。它支持ping测试、TCP测试、traceroute或tracert命令等路由跟踪、DNS查找、列出IP接口等。
Ping远程主机
Test NetConnection命令可以在没有任何参数或属性的情况下使用。如果没有任何参数或属性,此命令将对Microsoft提供的msedge.net域名进行ping测试。这个测试是关于简单的ping。
Test-NetConnection
输出如下。
ComputerName : internetbeacon.msedge.netRemoteAddress : 13.107.4.52InterfaceAlias : Ethernet0SourceAddress : 192.168.146.129PingSucceeded : TruePingReplyDetails (RTT) : 15 ms
- 计算机名 是测试和ping的远程系统主机名。
- 远程地址 是被测试和ping的远程系统IP地址。
- 接口IAS ping测试中使用的接口名称。
- 源地址 是本地系统的源接口IP地址。
- ping成功 是ping测试的结果,在这种情况下是正确的。
- PingReplyDetails公司 ping测试的时间大约是往返时间。
此外,我们还可以使用test NetConnection命令指定要用ping测试的远程主机。仅提供如下所示的远程系统主机名或IP地址。
Test-NetConnection google.com
输出与前面的命令输出度量如下所示。
ComputerName : google.comRemoteAddress : 216.58.206.206InterfaceAlias : Ethernet0SourceAddress : 192.168.146.129PingSucceeded : TruePingReplyDetails (RTT) : 57 ms
我们还可以指定要ping或测试网络连接的远程主机的IP地址。在下面的示例中,我们将ping IP地址216.58.206.206。
Test-NetConnection 216.58.206.206
详细Ping
Test NetConnection命令可以提供有关ping或测试网络连接的更多详细信息。-InformationLevel用于设置所提供或显示的信息和结果的级别或详细信息。我们还将提供“Detailed”作为参数进行详细ping。
Test-NetConnection -InformationLevel "Detailed" google.com
输出将如下所示,它将提供额外的详细信息,如 网络路由 , 名称解析结果 等等。
ComputerName : google.comRemoteAddress : 216.58.214.142NameResolutionResults : 216.58.214.142InterfaceAlias : Ethernet0SourceAddress : 192.168.146.129NetRoute (NextHop) : 192.168.146.2PingSucceeded : TruePingReplyDetails (RTT) : 154 ms
测试TCP连接和端口
Test NetConnection命令可用于测试远程TCP端口(如果它是可访问和打开的)。-Port属性用于指定端口号。
Test-NetConnection -Port 443 google.com
输出如下。这个 TcpTest成功 提供TCP端口测试结果,该结果在本例中为真。这仅仅意味着它是开放的。
ComputerName : google.comRemoteAddress : 216.58.206.174RemotePort : 443InterfaceAlias : Ethernet0SourceAddress : 192.168.146.129TcpTestSucceeded : True
测试远程主机连接
这个 -计算机名 还用于设置要通过ping操作测试的远程主机名。详细信息也可随附 -信息“详细” 属性。
Test-NetConnection -ComputerName "www.google.com" -InformationLevel "Detailed"
输出如下。
ComputerName : www.google.comRemoteAddress : 216.58.206.164NameResolutionResults : 216.58.206.164InterfaceAlias : Ethernet0SourceAddress : 192.168.146.129NetRoute (NextHop) : 192.168.146.2PingSucceeded : TruePingReplyDetails (RTT) : 64 ms
tracert或Print Trace Route
这个 路由跟踪 命令是流行的Windows命令,用于诊断、测试和打印到指定远程主机的网络路由。这种类型的跟踪路径信息可以用 -诊断路由 属性。
Test-NetConnection -DiagnoseRouting google.com
输出如下。
ComputerName : google.comRemoteAddress : 216.58.214.142SelectedSourceAddress : 192.168.146.129OutgoingInterfaceIndex : 6SelectedNetRoute : DestinationPrefix: 0.0.0.0/0NextHop: 192.168.146.2RouteDiagnosticsSucceeded : True
为了获得有关跟踪路由的更详细信息,应该使用 管理员 特权。在这之后 -信息级别“详细” 可以提供属性和参数。
Test-NetConnection -DiagnoseRouting -InformationLevel "Detailed" google.com
![图片[1]-PowerShell测试NetConnection教程-yiteyi-C++库](https://www.yiteyi.com/wp-content/uploads/2020/12/windowstect_image-23.png)
相关文章: 用于跟踪路由的Windows tracert命令