A Ruby API to nmap, the exploration tool and security / port scanner. Allows automating nmap and parsing nmap XML files.
- Provides a Ruby API for automating nmap.
- Provides a Parser for enumerating nmap XML scan files.
- Supports the full Nmap XML DTD.
Run Nmap from Ruby:
require'nmap/command'Nmap::Command.rundo |nmap|
nmap.connect_scan=truenmap.service_scan=truenmap.output_xml='scan.xml'nmap.verbose=truenmap.ports=[20,21,22,23,25,80,110,443,512,522,8080,1080]nmap.targets='192.168.1.*'endRun sudo nmap from Ruby:
require'nmap/command'Nmap::Command.sudodo |nmap|
nmap.syn_scan=truenmap.os_fingerprint=truenmap.service_scan=truenmap.output_xml='scan.xml'nmap.verbose=truenmap.ports=[20,21,22,23,25,80,110,443,512,522,8080,1080]nmap.targets='192.168.1.*'endParse Nmap XML scan files:
require'nmap/xml'Nmap::XML.open('scan.xml')do |xml|
xml.each_hostdo |host|
puts"[#{host.ip}]"host.each_portdo |port|
puts" #{port.number}/#{port.protocol}\t#{port.state}\t#{port.service}"endendendPrint NSE script output from an XML scan file:
require'nmap/xml'Nmap::XML.open('nse.xml')do |xml|
xml.each_hostdo |host|
puts"[#{host.ip}]"host.scripts.eachdo |name,output|
output.each_line{ |line| puts" #{line}"}endhost.each_portdo |port|
puts" [#{port.number}/#{port.protocol}]"port.scripts.eachdo |id,script|
puts" [#{id}]"script.output.each_line{ |line| puts" #{line}"}endendendend- ruby >= 2.0.0
- nmap >= 5.00
- nokogiri ~> 1.3
- command_mapper ~> 0.3
- Debian / Ubuntu:
$ sudo apt install nmap- Fedora / RedHat:
$ sudo dnf install nmap- Homebrew:
$ brew install nmap$ gem install ruby-nmapSee {file:LICENSE.txt} for license information.