Skip to content

Commit

Permalink
Merge pull request #716 from benPearce1/master
Browse files Browse the repository at this point in the history
Ensure the matched port is listening
  • Loading branch information
mizzy committed Apr 28, 2020
2 parents cf0bc01 + fbe4158 commit 8c9b56b
Showing 1 changed file with 2 additions and 1 deletion.
Expand Up @@ -5,9 +5,10 @@ function IsPortListening
$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)
$matchExpression = ("$ipaddress" + ":" + $portNumber + ".*LISTENING")
if ($protocol) { $matchExpression = ($protocol.toUpper() + "\s+$matchExpression") }
if ($netstatOutput -match $matchExpression) { return $true }
}
Expand Down

0 comments on commit 8c9b56b

Please sign in to comment.