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
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 = []
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
ports.select { |val| val if 'listen'.casecmp(val['state']) == 0 }
end
|