Sha256: c36ee7f579c9fc3b96ee42336c1abd98f2afd01066b2cafb869605783fb16122

Contents?: true

Size: 482 Bytes

Versions: 16

Compression:

Stored size: 482 Bytes

Contents

function IsPortListening
{
  param($portNumber, $protocol)
  $netstatOutput = netstat -an | Out-String
  $networkIPs = (Get-WmiObject Win32_NetworkAdapterConfiguration | ? {$_.IPEnabled}) | %{ $_.IPAddress[0] }
  foreach ($ipaddress in $networkIPs)
  {
    $matchExpression = ("$ipaddress" + ":" + $portNumber)
    if ($protocol) { $matchExpression = ($protocol.toUpper() + "\s+$matchExpression") }    
    if ($netstatOutput -match $matchExpression) { return $true }
  }
  $false
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
serverspec-0.10.6 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.10.5 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.10.4 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.10.3 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.10.2 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.10.1 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.10.0 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.8 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.7 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.6 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.5 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.4 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.3 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.2 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.1 lib/serverspec/backend/powershell/support/is_port_listening.ps1
serverspec-0.9.0 lib/serverspec/backend/powershell/support/is_port_listening.ps1