lib/nmap/xml.rb in ruby-nmap-0.1.1 vs lib/nmap/xml.rb in ruby-nmap-0.2.0

- old
+ new

@@ -1,8 +1,9 @@ -require 'nmap/host' require 'nmap/scanner' +require 'nmap/scan_task' require 'nmap/scan' +require 'nmap/host' require 'nokogiri' require 'enumerator' module Nmap @@ -40,11 +41,12 @@ # def scanner @scanner ||= Scanner.new( @doc.root['scanner'], @doc.root['version'], - @doc.root['args'] + @doc.root['args'], + Time.at(@doc.root['start'].to_i) ) end # # Parses the XML scan file version. @@ -61,11 +63,11 @@ # # @return [Array<Scan>] # The scan information. # def scan_info - @doc.xpath("/nmaprun/scaninfo").map do |scaninfo| + @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?('-') @@ -83,24 +85,45 @@ # # @return [Integer] # The verbose level. # def verbose - @verbose ||= @doc.at("verbose/@level").inner_text.to_i + @verbose ||= @doc.at('verbose/@level').inner_text.to_i end # # Parses the debugging level. # # @return [Integer] # The debugging level. # def debugging - @debugging ||= @doc.at("debugging/@level").inner_text.to_i + @debugging ||= @doc.at('debugging/@level').inner_text.to_i end # + # Parses the tasks of the scan. + # + # @return [Array<ScanTask>] + # The tasks of the scan. + # + # @since 0.1.2 + # + 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 + + # # Parses the hosts in the scan. # # @yield [host] # Each host will be passed to a given block. # @@ -109,10 +132,10 @@ # # @return [XML] # The XML object. # def each_host(&block) - @doc.xpath("/nmaprun/host").each do |host| + @doc.xpath('/nmaprun/host').each do |host| block.call(Host.new(host)) if block end return self end