-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsernmap
49 lines (40 loc) · 1.31 KB
/
parsernmap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
#############################
# Author = Royce Davis, Alexander Alexandrov
# Last edited August 7, 2023
#############################
require 'rubygems'
require 'nmap/parser'
unless ARGV.length > 0
puts "Generates a .txt file containing the open ports summary and the .nmap information\r\n"
puts "USAGE:\t./parsenmap <nmap xml file>\r\n\n"
exit!
end
def current_datetime
Time.now.strftime("Date_%Y-%m-%d_%H-%M-%S")
end
nmap_file = ARGV[0]
output_file = "Report_#{File.basename(nmap_file, '.xml')}_#{current_datetime}.txt"
ports = Array.new
portstring = String.new
result_string = String.new
parser = Nmap::Parser.parsefile(nmap_file)
parser.hosts("up") do |host|
[:tcp, :udp].each do |type|
host.getports(type, "open") do |port|
string = port.state.to_s
unless string.include? "filtered"
srv = port.service
ports << port.num unless ports.include? port.num
result_string << "#{host.addr}\t#{port.num}\t#{srv.name}\t#{srv.product}\t#{srv.version}\t#{srv.extrainfo}\n"
end
end
end
end
puts result_string
File.open(output_file, "w") do |file|
file.write(result_string)
end
ports.each { |port| portstring << port.to_s + "," }
puts "Results saved to #{output_file}"
puts "sudo nmap -sS -p #{portstring.chop} -sV -A -vv -oA enumeration -iL ../ranges.txt"