Nmap

    Ruby-nmap gem is a Ruby interface to nmap, the exploration tool and security / port scanner.

    • Provides a Ruby interface for running nmap.
    • Provides a Parser for enumerating nmap XML scan files.
    1. scan = Nmap::Program.scan(:targets => '192.168.0.15', :verbose => true)

    each option like nmap.syn_scan or nmap.xml is considered as a Task. Documentation shows the list of that are supported by the lib.

    1. #!/usr/bin/env ruby
    2. # KING SABRI | @KINGSABRI
    3. require 'nmap/program'
    4. Nmap::Program.scan do |nmap|
    5. # Target
    6. nmap.targets = '192.168.0.1'
    7. # Verbosity and Debugging
    8. nmap.show_reason = true
    9. nmap.syn_scan = true # You can use nmap.all like -A in nmap
    10. # Service/Version Detection:
    11. nmap.service_scan = true
    12. nmap.os_fingerprint = true
    13. nmap.version_all = true
    14. # Script scanning
    15. nmap.script = "all"
    16. nmap.all_ports # nmap.ports = (0..65535).to_a
    17. # Firewall/IDS Evasion and Spoofing:
    18. nmap.decoys = ["google.com","yahoo.com","hotmail.com","facebook.com"]
    19. nmap.spoof_mac = "00:11:22:33:44:55"
    20. nmap.max_parallelism = 130
    21. # Scan outputs
    22. nmap.output_all = 'rubyfu_scan'
    23. end

    I quoted the code from official documentation (https://github.com/sophsec/ruby-nmap)

    1. require 'nmap/xml'
    2. Nmap::XML.new(ARGV[0]) do |xml|
    3. xml.each_host do |host|
    4. puts "[#{host.ip}]"
    5. # Print: Port/Protocol port_status service_name
    6. host.each_port do |port|
    7. puts " #{port.number}/#{port.protocol}\t#{port.state}\t#{port.service}"
    8. end
    9. end