Class: Inspec::Resources::WindowsPorts

Inherits:
PortsInfo
  • Object
show all
Defined in:
lib/resources/port.rb

Overview

TODO: Add UDP infromation Get-NetUDPEndpoint TODO: currently Windows only supports tcp ports TODO: Get-NetTCPConnection does not return PIDs TODO: double-check output with ‘netstat -ano’

Instance Attribute Summary

Attributes inherited from PortsInfo

#inspec

Instance Method Summary collapse

Methods inherited from PortsInfo

#initialize

Constructor Details

This class inherits a constructor from Inspec::Resources::PortsInfo

Instance Method Details

#infoObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/resources/port.rb', line 120

def info
  # get all port information
  cmd = inspec.command('Get-NetTCPConnection | Select-Object -Property State, Caption, Description, LocalAddress, LocalPort, RemoteAddress, RemotePort, DisplayName, Status | ConvertTo-Json')

  begin
    ports = JSON.parse(cmd.stdout)
  rescue JSON::ParserError => _e
    return nil
  end

  return nil if ports.nil?

  ports.map { |x|
    {
      port: x['LocalPort'],
      address: x['LocalAddress'],
      protocol: 'tcp',
      process: nil,
      pid: nil,
    }
  }
end