Sha256: 40d4cb019573065ad3341fa1f102abec5cc4b3066e0278888d9e974923a12d8d
Contents?: true
Size: 600 Bytes
Versions: 6
Compression:
Stored size: 600 Bytes
Contents
function IsPortListening { param($portNumber, $protocol) $netstatOutput = netstat -an | Out-String $networkIPs = (Get-WmiObject Win32_NetworkAdapterConfiguration | ? {$_.IPEnabled}) | %{ $_.IPAddress[0] } [array] $networkIPs += "0.0.0.0" [array] $networkIPs += "127.0.0.1" [array] $networkIPs += "[::1]" foreach ($ipaddress in $networkIPs) { $matchExpression = ("$ipaddress" + ":" + $portNumber + ".*LISTENING") if ($protocol) { $matchExpression = ($protocol.toUpper() + "\s+$matchExpression") } if ($netstatOutput -match $matchExpression) { return $true } } $false }
Version data entries
6 entries across 6 versions & 1 rubygems