PowerShell 测试网络连接

在Windows 2012 R2或者8.1上,你还在使用Ping吗? 2


相信很多朋友已经注意到作为Ping的扩展的一个PowerShell 命令已经出来一段时间了。在Windwos server 2012 R2或者Windows 8.1 上面,一个谓之Test-NetConnection的命令与先前的Ping相比,可以做更多很酷的事情。

首先如果你只是想检测互联网的连接,可以使用微软网关某个内置的地址(这个地址通过http连接,会直接跳到bing.com)去检测。

PS> Test-NetConnection

ComputerName           : internetbeacon.msedge.net
RemoteAddress          : 131.253.3.197
InterfaceAlias         : Ethernet
SourceAddress          : 172.8.8.8
PingSucceeded          : True
PingReplyDetails (RTT) : 59 ms

Test-NetConnection还可以接受目标地址参数

PS> Test-NetConnection 204.79.197.200

ComputerName           : 204.79.197.200
RemoteAddress          : 204.79.197.200
InterfaceAlias         : Ethernet
SourceAddress          : 172.18.8.8
PingSucceeded          : True
PingReplyDetails (RTT) : 59 ms

当然也可以接收DNS记录的域名:

PS> Test-NetConnection -ComputerName pstips.net

ComputerName           : pstips.net
RemoteAddress          : 103.251.88.111
InterfaceAlias         : Ethernet
SourceAddress          : 172.18.8.8
PingSucceeded          : True
PingReplyDetails (RTT) : 58 ms

这还不是全部,它还可以检测某个端口是不是打开(比如因为什么原因你的网络中禁ping)

PowerShell 测试网络连接

PowerShell 测试网络连接

它还可以使用-CommonTCPPort 支持输入WINRM,Http,RDP,SMB等枚举值。

PS> Test-NetConnection -ComputerName pstips.net -CommonTCPPort http

ComputerName           : pstips.net
RemoteAddress          : 103.251.88.111
RemotePort             : 80
InterfaceAlias         : Ethernet
SourceAddress          : 172.18.8.8
PingSucceeded          : True
PingReplyDetails (RTT) : 59 ms
TcpTestSucceeded       : True

最后一个例子,这条命令还有一个-traceTroute(路由跟踪)的参数选项

PS> Test-NetConnection pstips.net -TraceRoute

ComputerName           : pstips.net
RemoteAddress          : 103.251.88.111
InterfaceAlias         : Ethernet
SourceAddress          : 10.218.188.30
PingSucceeded          : True
PingReplyDetails (RTT) : 177 ms
TraceRoute             : 10.218.188.2
                         10.37.222.5
                         10.37.222.2
                         10.37.67.177
                         10.37.44.98
                         10.37.67.226
                         10.37.45.77
                         131.107.202.166
                         131.107.201.250
                         207.46.36.225
                         207.46.46.161
                         205.177.32.29
                         63.218.210.50
                         63.218.210.50
                         63.218.11.10
                         123.242.225.2
                         103.251.88.111

原文链接:Still using Ping when you are running Windows 2012 R2/8.1?

原文作者:Niklas Åkerlund

翻译: 荔非苔

 

本文链接: https://www.pstips.net/still-using-ping-when-you-are-running-windows-2012-r28-1.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

关于 Mooser Lee

我是一个Powershell的爱好者,创建了PowerShell中文博客,热衷于Powershell技术的搜集和分享。本站部分内容来源于互联网,不足之处敬请谅解,并欢迎您批评指正。

回复 张杰 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

2 条评论 “在Windows 2012 R2或者8.1上,你还在使用Ping吗?