Sha256: e70ee3b0a9b264b71fa55405afa79dcabe90f73daa236c901dbf8a2c089ae707

Contents?: true

Size: 1.43 KB

Versions: 467

Compression:

Stored size: 1.43 KB

Contents

function IsRemotePortListening{
	param(
		[string]$hostname,
		[string]$proto="tcp",
		[int]$port,
		[int]$timeout)


	If ($proto -eq "tcp") {     
		$tcpobject = new-Object system.Net.Sockets.TcpClient                   
		$connect = $tcpobject.BeginConnect($hostname,$port,$null,$null)   
		$wait = $connect.AsyncWaitHandle.WaitOne($timeout * 1000,$false)   
		#If timeout   
		If(!$wait) {   
				$tcpobject.Close()   
				return $false
			} 
			else{    
				$result = $tcpobject.Connected
				$tcpobject.Close()
				return $result
			}      
		}       
		elseif ($proto -eq "udp") {                               
			$udpobject = new-Object system.Net.Sockets.Udpclient 
			$udpobject.client.ReceiveTimeout = $timeout  * 1000
			$udpobject.Connect($hostname,$port)  
			$a = new-object system.text.asciiencoding  
			$byte = $a.GetBytes("$(Get-Date)")  
			[void]$udpobject.Send($byte,$byte.length)  
			$remoteendpoint = New-Object system.net.ipendpoint([system.net.ipaddress]::Any,0)  
			try{
				#Blocks until a message returns on this socket from a remote host.  
				$receivebytes = $udpobject.Receive([ref]$remoteendpoint)  
				[string]$returndata = $a.GetString($receivebytes) 
				If ($returndata) { 
					$udpobject.close()    
					return $true
				} 
				else{
					return $false
				}                        
			}
			catch{
				return $false
			}
		}         
		else{
			throw "Protocol ${proto} not supported"
		}                          
	}   

Version data entries

467 entries across 467 versions & 3 rubygems

Version Path
specinfra-2.76.5 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.76.4 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.76.3 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.76.2 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.76.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.76.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.75.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-rb19-2.44.7 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.75.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.74.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.73.4 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.73.3 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.73.2 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.73.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.73.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.72.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.72.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.71.3 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.71.2 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.71.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1