lib/ruby-nessus/host.rb in ruby-nessus-0.1.1 vs lib/ruby-nessus/host.rb in ruby-nessus-0.1.2

- old
+ new

@@ -41,11 +41,11 @@ # Return the host run time. # @return [String] # The Host Scan Run Time # @example # scan.scan_run_time #=> '2 hours 5 minutes and 16 seconds' - def scan_run_time + def scan_runtime if scan_start_time.empty? | scan_stop_time.empty?; return "N/A"; end h = ("#{Time.parse(scan_stop_time).strftime('%H').to_i - Time.parse(scan_start_time).strftime('%H').to_i}").gsub('-', '') m = ("#{Time.parse(scan_stop_time).strftime('%M').to_i - Time.parse(scan_start_time).strftime('%M').to_i}").gsub('-', '') s = ("#{Time.parse(scan_stop_time).strftime('%S').to_i - Time.parse(scan_start_time).strftime('%S').to_i}").gsub('-', '') return "#{h} hours #{m} minutes and #{s} seconds" @@ -66,10 +66,11 @@ # @example # host.mac_addr #=> "00:11:22:33:44:55" def mac_addr @mac_addr ||= @host.at('mac_addr').inner_text end + alias mac_address mac_addr # Return the Host DNS Name. # @return [String] # Return the Host DNS Name # @example @@ -84,46 +85,47 @@ # @example # host.dns_name #=> "Microsoft Windows 2000, Microsoft Windows Server 2003" def os_name @os_name ||= @host.at('os_name').inner_text end + alias operating_system os_name - # Return the scanned port count for a given host object. + # Return the open ports for a given host object. # @return [Integer] - # Return the Scanned Port Count For A Given Host Object. + # Return the open ports for a given host object. # @example - # host.scanned_ports_count #=> 213 - def scanned_ports_count + # host.open_ports #=> 213 + def open_ports @scanned_ports ||= @host.at('num_ports').inner_text.to_i end # Returns All Informational Event Objects For A Given Host. # @yield [prog] If a block is given, it will be passed the newly # created Event object. # @yieldparam [EVENT] prog The newly created Event object. # @return [Integer] # Return The Informational Event Count For A Given Host. # @example - # host.informational_severity_events do |info| - # puts info.name if info.name + # host.informational_events do |info| + # puts info.port + # puts info.data if info.data # end - def informational_severity_events(&block) - unless @informational_severity_events - @informational_severity_events = [] - @informational_severity_count = 0 + def informational_events(&block) + unless @informational_events + @informational_events = [] + @informational_event_count = 0 @host.xpath("//ReportItem").each do |event| next if event.at('severity').inner_text.to_i != 0 - @informational_severity_events << Event.new(event) - @informational_severity_count += 1 + @informational_events << Event.new(event) + @informational_event_count += 1 end - - @informational_severity_count = @host.at('num_lo').inner_text.to_i + end - @informational_severity_events.each(&block) - return @informational_severity_count + @informational_events.each(&block) + return @informational_event_count end # Returns All Low Event Objects For A Given Host. # @yield [prog] If a block is given, it will be passed the newly # created Event object. @@ -133,19 +135,21 @@ # @example # host.low_severity_events do |low| # puts low.name if low.name # end def low_severity_events(&block) + + @low_severity_count = @host.at('num_lo').inner_text.to_i + unless @low_severity_events @low_severity_events = [] @host.xpath("//ReportItem").each do |event| next if event.at('severity').inner_text.to_i != 1 @low_severity_events << Event.new(event) end - @low_severity_count = @host.at('num_lo').inner_text.to_i end @low_severity_events.each(&block) return @low_severity_count end @@ -159,19 +163,21 @@ # @example # host.medium_severity_events do |medium| # puts medium.name if medium.name # end def medium_severity_events(&block) + + @high_severity_count = @host.at('num_med').inner_text.to_i + unless @medium_severity_events @medium_severity_events = [] @host.xpath("//ReportItem").each do |event| next if event.at('severity').inner_text.to_i != 2 @medium_severity_events << Event.new(event) end - @high_severity_count = @host.at('num_med').inner_text.to_i end @medium_severity_events.each(&block) return @high_severity_count end @@ -185,19 +191,21 @@ # @example # host.high_severity_events do |high| # puts high.name if high.name # end def high_severity_events(&block) + + @high_severity_count = @host.at('num_hi').inner_text.to_i + unless @high_severity_events @high_severity_events = [] @host.xpath("//ReportItem").each do |event| next if event.at('severity').inner_text.to_i != 3 @high_severity_events << Event.new(event) end - - @high_severity_count = @host.at('num_hi').inner_text.to_i + end @high_severity_events.each(&block) return @high_severity_count end @@ -206,10 +214,10 @@ # @return [Integer] # Return the total event count for a given host. # @example # host.event_count #=> 3456 def event_count - (informational_severity_events + low_severity_events + medium_severity_events + high_severity_events).to_i + ((low_severity_events.to_i) + (medium_severity_events.to_i) + (high_severity_events.to_i)).to_i end # Creates a new Event object to be parser # @yield [prog] If a block is given, it will be passed the newly # created Event object.