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

Version Path
specinfra-2.82.21 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.82.20 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.82.19 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.82.18 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.82.17 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.82.16 lib/specinfra/backend/powershell/support/is_port_listening.ps1