Class: Inspec::Resources::SolarisPorts
- Inherits:
-
FreeBsdPorts
- Object
- PortsInfo
- FreeBsdPorts
- Inspec::Resources::SolarisPorts
- Includes:
- SolarisNetstatParser
- Defined in:
- lib/resources/port.rb
Instance Attribute Summary
Attributes inherited from PortsInfo
Instance Method Summary collapse
Methods included from SolarisNetstatParser
Methods inherited from FreeBsdPorts
#parse_net_address, #parse_sockstat_line
Methods inherited from PortsInfo
Constructor Details
This class inherits a constructor from Inspec::Resources::PortsInfo
Instance Method Details
#info ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/resources/port.rb', line 396 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) { 'port' => port, 'address' => host, 'protocol' => protocol, } } ports end |