Class: Inspec::Resources::SolarisPorts

Inherits:
FreeBsdPorts show all
Includes:
SolarisNetstatParser
Defined in:
lib/resources/port.rb

Instance Attribute Summary

Attributes inherited from PortsInfo

#inspec

Instance Method Summary collapse

Methods included from SolarisNetstatParser

#parse_netstat

Methods inherited from FreeBsdPorts

#parse_net_address, #parse_sockstat_line

Methods inherited from PortsInfo

#initialize

Constructor Details

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

Instance Method Details

#infoObject



697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'lib/resources/port.rb', line 697

def info
  # extract all port info
  cmd = inspec.command('netstat -an -f inet -f inet6')
  return nil if cmd.exit_status.to_i != 0

  # parse the content
  netstat_ports = parse_netstat(cmd.stdout)

  # filter all ports, where we `listen`
  listen = netstat_ports.select { |val|
    !val['state'].nil? && 'listen'.casecmp(val['state']) == 0
  }

  # map the data
  ports = listen.map { |val|
    protocol = val['protocol']
    local_addr = val['local-address']

    # solaris uses 127.0.0.1.57455 instead 127.0.0.1:57455, lets convert the
    # the last . to :
    local_addr[local_addr.rindex('.')] = ':'
    host, port = parse_net_address(local_addr, protocol)
    if host.nil?
      nil
    else
      {
        'port'     => port,
        'address'  => host,
        'protocol' => protocol,
      }
    end
  }
  ports.compact
end