【问题标题】:PowerShell command to check the connection between IPaddress and port in Windows Server 2008 R2PowerShell 命令检查 Windows Server 2008 R2 中 IP 地址和端口之间的连接
【发布时间】:2017-06-25 01:58:30
【问题描述】:

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

Test-NetConnection localhost -Port 445

此命令与-InformationLevel 一起返回TRUEFALSE,具体取决于结果。这正是我想要的。

我需要在 Windows Server 2008 R2 上运行相同的检查。我知道Test-NetConnection 命令在Server 2008 上不起作用。我找不到任何其他命令来检查机器IP 和端口之间的连接并返回TRUEFALSE。谁能为此建议一个替代的 PowerShell 命令?

【问题讨论】:

标签: windows powershell powershell-2.0 windows-server-2008 windows-server-2008-r2


【解决方案1】:

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

有许多variants 使用System.Net.Sockets.TcpClientSystem.Net.Sockets.UdpClient .Net classes 使用ConnectBeginConnect 方法。

【讨论】:

  • 我想要检查 IP 地址与端口的连接。所以我做了以下事情,它奏效了。 $tcpobject = new-Object system.Net.Sockets.TcpClient $connect = $tcpobject.BeginConnect($computer,$port,$null,$null) #配置退出前超时 $wait = $connect.AsyncWaitHandle.WaitOne(1000, $false) 完整答案请查看here
【解决方案2】:

您可以使用 NetStat 工具 阅读更多关于 NetStat here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2012-05-25
    相关资源
    最近更新 更多