Sha256: 13c8b909b5b52ac544cd15f5855b96efb471f423bf3628545ecab7cdcace2ff4

Contents?: true

Size: 640 Bytes

Versions: 24

Compression:

Stored size: 640 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]"
  [array] $networkIPs += "[::]"
  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

24 entries across 24 versions & 1 rubygems

Version Path
specinfra-2.91.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.90.1 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.90.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.89.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.88.2 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.88.1 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.88.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.87.2 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.87.1 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.87.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.86.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.85.1 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.85.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.84.1 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.84.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.83.4 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.83.3 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.83.2 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.83.1 lib/specinfra/backend/powershell/support/is_port_listening.ps1
specinfra-2.83.0 lib/specinfra/backend/powershell/support/is_port_listening.ps1