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.91.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.90.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.90.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.89.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.88.2 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.88.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.88.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.87.2 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.87.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.87.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.86.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.85.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.85.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.84.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.84.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.83.4 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.83.3 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.83.2 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.83.1 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1
specinfra-2.83.0 lib/specinfra/backend/powershell/support/is_remote_port_listening.ps1