168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/resources/port.rb', line 168
def info
ports = []
fail 'Please ensure `lsof` is available on the machine.' if !inspec.command(@lsof.to_s).exist?
lsof_cmd = inspec.command("#{@lsof} -nP -i -FpctPn")
return nil if lsof_cmd.exit_status.to_i != 0
lsof_parser(lsof_cmd).each do |process, port_ids|
pid, cmd = process.split(':')
port_ids.each do |port_str|
ipv, proto, port, host = port_str.split(':', 4)
ports.push({ 'port' => port.to_i,
'address' => host,
'protocol' => ipv == 'ipv6' ? proto + '6' : proto,
'process' => cmd,
'pid' => pid.to_i })
end
end
ports
end
|