$IP ="220.181.111.142"
$Port ="801"
Function Port-Test ($IP,$Port)
{
$Timeout = 1000
$Address = [System.Net.IPAddress]::Parse($IP)
$Socket = New-Object System.Net.Sockets.TCPClient
$Connect = $Socket.BeginConnect($Address,$Port,$null,$null)
Start-Sleep -Milliseconds 100
If ( $Connect.IsCompleted )
{
$Wait = $Connect.AsyncWaitHandle.WaitOne($TimeOut,$false)
If(!$Wait)
{
$Socket.Close()
Return $false
}
Else{
$Socket.EndConnect($Connect)
$Socket.Close()
Return $true
}
}
Else{Return $false}
}
Port-Test $ip $Port