Telnet端口测试

$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

posted on 2013-12-12 14:48  momingliu11  阅读(631)  评论(0编辑  收藏  举报