test-port --powershell 脚本
function Test-Port { Param( [string]$ComputerName="localhost", $Port = 5985, $Timeout = 1000 ) try { $tcpclient = New-Object -TypeName system.Net.Sockets.TcpClient $iar = $tcpclient.BeginConnect($ComputerName,$Port,$null,$null) $wait = $iar.AsyncWaitHandle.WaitOne($Timeout,$false) if(!$wait) { $tcpclient.Close() return $false } else { $null = $tcpclient.EndConnect($iar) $tcpclient.Close() return $true } } catch { $false } }