PowerShell 命令检查 Windows Server 2008 R2 中 IP 地址和端口之间的连接

PowerShell command to check the connection between IPaddress and port in Windows Server 2008 R2

我正在 Windows Server 2012 R2 上使用 PowerShell 脚本。我正在检查带有端口的机器的测试连接。以下 PowerShell 命令正在运行:

Test-NetConnection localhost -Port 445

此命令连同 -InformationLevel return 根据结果 TRUEFALSE。这正是我想要的。

我需要 运行 在 Windows Server 2008 R2 上进行相同的检查。我知道 Test-NetConnection 命令在 Server 2008 上不起作用。我找不到任何其他命令来检查 machineIP 和端口之间的连接以及 return 是否 TRUEFALSE .有人可以为此建议一个替代的 PowerShell 命令吗?

这是来自 Boe Prox TechNet Script Center 的脚本。

有许多 variants out there that make use of the System.Net.Sockets.TcpClient and System.Net.Sockets.UdpClient .Net classes 使用 ConnectBeginConnect 方法。

您可以使用 NetStat 工具 阅读有关 NetStat 的更多信息 here