Class: Nmap::XML
Overview
Represents an Nmap XML file.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Path of the Nmap XML scan file.
Instance Method Summary collapse
-
#debugging ⇒ Integer
Parses the debugging level.
-
#each(&block) ⇒ Object
Parses the hosts that were found to be up during the scan.
-
#each_host {|host| ... } ⇒ XML, Enumerator
Parses the hosts in the scan.
-
#each_up_host {|host| ... } ⇒ XML, Enumerator
Parses the hosts that were found to be up during the scan.
-
#hosts ⇒ Array<Host>
Parses the hosts in the scan.
-
#initialize(path) {|xml| ... } ⇒ XML
constructor
Creates a new XML object.
-
#scan_info ⇒ Array<Scan>
Parses the scan information.
-
#scanner ⇒ Scanner
Parses the scanner information.
-
#tasks ⇒ Array<ScanTask>
Parses the tasks of the scan.
-
#to_s ⇒ String
Converts the XML parser to a String.
-
#up_hosts ⇒ Array<Host>
Parses the hosts found to be up during the scan.
-
#verbose ⇒ Integer
Parses the verbose level.
-
#version ⇒ String
Parses the XML scan file version.
Constructor Details
#initialize(path) {|xml| ... } ⇒ XML
Creates a new XML object.
31 32 33 34 35 36 |
# File 'lib/nmap/xml.rb', line 31 def initialize(path) @path = File.(path) @doc = Nokogiri::XML(open(@path)) yield self if block_given? end |
Instance Attribute Details
#path ⇒ Object (readonly)
Path of the Nmap XML scan file
17 18 19 |
# File 'lib/nmap/xml.rb', line 17 def path @path end |
Instance Method Details
#debugging ⇒ Integer
Parses the debugging level.
101 102 103 |
# File 'lib/nmap/xml.rb', line 101 def debugging @debugging ||= @doc.at('debugging/@level').inner_text.to_i end |
#each(&block) ⇒ Object
Parses the hosts that were found to be up during the scan.
197 198 199 |
# File 'lib/nmap/xml.rb', line 197 def each(&block) each_up_host(&block) end |
#each_host {|host| ... } ⇒ XML, Enumerator
Parses the hosts in the scan.
139 140 141 142 143 144 145 146 147 |
# File 'lib/nmap/xml.rb', line 139 def each_host(&block) return enum_for(__method__) unless block @doc.xpath('/nmaprun/host').each do |host| Host.new(host,&block) end return self end |
#each_up_host {|host| ... } ⇒ XML, Enumerator
Parses the hosts that were found to be up during the scan.
172 173 174 175 176 177 178 179 180 |
# File 'lib/nmap/xml.rb', line 172 def each_up_host(&block) return enum_for(__method__) unless block @doc.xpath("/nmaprun/host[status[@state='up']]").each do |host| Host.new(host,&block) end return self end |
#hosts ⇒ Array<Host>
Parses the hosts in the scan.
155 156 157 |
# File 'lib/nmap/xml.rb', line 155 def hosts each_host.to_a end |
#scan_info ⇒ Array<Scan>
Parses the scan information.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/nmap/xml.rb', line 69 def scan_info @doc.xpath('/nmaprun/scaninfo').map do |scaninfo| Scan.new( scaninfo['type'].to_sym, scaninfo['protocol'].to_sym, scaninfo['services'].split(',').map { |ports| if ports.include?('-') Range.new(*(ports.split('-',2))) else ports.to_i end } ) end end |
#scanner ⇒ Scanner
Parses the scanner information.
44 45 46 47 48 49 50 51 |
# File 'lib/nmap/xml.rb', line 44 def scanner @scanner ||= Scanner.new( @doc.root['scanner'], @doc.root['version'], @doc.root['args'], Time.at(@doc.root['start'].to_i) ) end |
#tasks ⇒ Array<ScanTask>
Parses the tasks of the scan.
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/nmap/xml.rb', line 113 def tasks @doc.xpath('/nmaprun/taskbegin').map do |task_begin| task_end = task_begin.xpath('following-sibling::taskend').first ScanTask.new( task_begin['task'], Time.at(task_begin['time'].to_i), Time.at(task_end['time'].to_i), task_end['extrainfo'] ) end end |
#to_s ⇒ String
Converts the XML parser to a String.
207 208 209 |
# File 'lib/nmap/xml.rb', line 207 def to_s @path.to_s end |
#up_hosts ⇒ Array<Host>
Parses the hosts found to be up during the scan.
188 189 190 |
# File 'lib/nmap/xml.rb', line 188 def up_hosts each_up_host.to_a end |
#verbose ⇒ Integer
Parses the verbose level.
91 92 93 |
# File 'lib/nmap/xml.rb', line 91 def verbose @verbose ||= @doc.at('verbose/@level').inner_text.to_i end |
#version ⇒ String
Parses the XML scan file version.
59 60 61 |
# File 'lib/nmap/xml.rb', line 59 def version @version ||= @doc.root['xmloutputversion'] end |