Method: Inspec::Resources::WindowsPorts#info

Defined in:
lib/resources/port.rb

#infoObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/resources/port.rb', line 115

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