function Test-Port
{
    Param([string]$ComputerName,$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
        {
            # Close the connection and report the error if there is one
             
            $null = $tcpclient.EndConnect($iar)
            $tcpclient.Close()
            return $true
        }
    }
    catch
    {
        $false
    }
}

 

相关文章:

  • 2021-12-22
  • 2021-10-02
  • 2021-10-17
  • 2021-11-15
  • 2021-10-04
  • 2022-03-04
  • 2021-09-19
  • 2022-12-23
猜你喜欢
  • 2022-01-18
  • 2022-02-05
  • 2021-12-08
  • 2022-02-07
  • 2022-01-04
  • 2022-12-23
相关资源
相似解决方案