Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function testport
- {
- param
- (
- [Parameter(Mandatory = $True)]
- [string]$hostname,
- [string]$port,
- [string]$timeout
- )
- $requestcallback = $null
- $state = $null
- try {
- $client = New-Object System.Net.Sockets.TcpClient
- $client.BeginConnect($hostname,$port,$requestCallback,$state)
- Start-Sleep -milli $timeOut
- if ($client.Connected)
- {
- $open = $true
- }
- else
- {
- $open = $false
- }
- }
- catch {
- write-host "Error connecting to socket!"
- }
- $client.Close()
- return $open
- }
Advertisement
Add Comment
Please, Sign In to add comment