class Inspec::Resources::SolarisPorts
Public Instance Methods
info()
click to toggle source
# File lib/inspec/resources/port.rb, line 714 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 do |val| !val["state"].nil? && "listen".casecmp(val["state"]) == 0 end # map the data ports = listen.map do |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 end ports.compact end