Skip to content

Instantly share code, notes, and snippets.

@activeshadow
Created May 10, 2015 01:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save activeshadow/ebb05a0935941b10864b to your computer and use it in GitHub Desktop.
Save activeshadow/ebb05a0935941b10864b to your computer and use it in GitHub Desktop.
Generate Markdown table of open ports from Nmap scan results
host_addr = %r{Host: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})}
open_port = %r{([0-9]+)/open/}
ports = {}
ARGV.each do |f|
File.foreach(f) do |l|
l.scan(host_addr) do |a|
l.scan(open_port) do |p|
ports[a.first] = [] unless ports.key?(a.first)
ports[a.first] << p.first.to_i
end
end
end
end
puts 'Host | Listening Ports'
puts ':--: | :-------------:'
ports.each do |a,p|
puts "#{a} | **TCP:** #{p.uniq.sort.join(', ')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment