Skip to content

Repository files navigation

ruby-nmap

CICode ClimateGem Version

Description

A Ruby API to nmap, the exploration tool and security / port scanner. Allows automating nmap and parsing nmap XML files.

Features

  • Provides a Ruby API for automating nmap.
  • Provides a Parser for enumerating nmap XML scan files.
  • Supports the full Nmap XML DTD.

Examples

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.*'end

Run 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.*'end

Parse 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}"endendend

Print 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

Requirements

Install

  • Debian / Ubuntu:
$ sudo apt install nmap
  • Fedora / RedHat:
$ sudo dnf install nmap
  • Homebrew:
$ brew install nmap
$ gem install ruby-nmap

License

See {file:LICENSE.txt} for license information.

About

A Ruby interface to nmap, the exploration tool and security / port scanner. Allows automating nmap and parsing nmap XML files.

Topics

Resources

Stars

298 stars

Watchers

18 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages