Method: Inspec::Resources::HpuxPorts#info

Defined in:
lib/resources/port.rb

#infoObject



731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# File 'lib/resources/port.rb', line 731

def info
  ## Can't use 'netstat -an -f inet -f inet6' as the latter -f option overrides the former one and return only inet ports
  cmd1 = inspec.command('netstat -an -f inet')
  return nil if cmd1.exit_status.to_i != 0
  cmd2 = inspec.command('netstat -an -f inet6')
  return nil if cmd2.exit_status.to_i != 0
  cmd = cmd1.stdout + cmd2.stdout
  ports = []
  # parse all lines
  cmd.each_line do |line|
    port_info = parse_netstat_line(line)
    next unless %w{tcp tcp6 udp udp6}.include?(port_info['protocol'])
    ports.push(port_info)
  end
  # select all ports, where we `listen`
  ports.select { |val| val if 'listen'.casecmp(val['state']) == 0 }
end