class RubyNessus::Version1::Host

Public Class Methods

new(host) click to toggle source

Creates A New Host Object @param [Object] Host Object @example Host.new(object)

# File lib/ruby-nessus/version1/host.rb, line 12
def initialize(host)
  @host = host
end

Public Instance Methods

dns_name() click to toggle source

Return the Host DNS Name. @return [String]

Return the Host DNS Name

@example

host.dns_name #=> "snorby.org"
# File lib/ruby-nessus/version1/host.rb, line 90
def dns_name
  @dns_name ||= @host.at('dns_name').inner_text
end
each_event() { |event| ... } click to toggle source

Creates a new Event object to be parser @yield [prog] If a block is given, it will be passed the newly

created Event object.

@yieldparam [EVENT] prog The newly created Event object. @example

host.events do |event|
  puts event.name if event.name
  puts event.port
end
# File lib/ruby-nessus/version1/host.rb, line 240
def each_event(&block)
  @host.xpath('ReportItem').each do |event|
    yield(Event.new(event)) if block
  end
end
event_count() click to toggle source

Return the total event count for a given host. @return [Integer]

Return the total event count for a given host.

@example

host.event_count #=> 3456
# File lib/ruby-nessus/version1/host.rb, line 227
def event_count
  (low_severity_events.to_i + medium_severity_events.to_i + high_severity_events.to_i).to_i
end
events() click to toggle source

Parses the events of the host. @return [Array<String>]

The events of the host.
# File lib/ruby-nessus/version1/host.rb, line 249
def events
  to_enum(:each_event).to_a
end
high_severity_events(&block) click to toggle source

Returns All High 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 High Event Count For A Given Host.

@example

host.high_severity_events do |high|
  puts high.name if high.name
end
# File lib/ruby-nessus/version1/host.rb, line 205
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

  end

  @high_severity_events.each(&block)
  @high_severity_count
end
hostname() click to toggle source

Return the Host Object hostname. @return [String]

The Host Object Hostname

@example

host.hostname #=> "127.0.0.1"
# File lib/ruby-nessus/version1/host.rb, line 25
def hostname
  @hostname ||= @host.at('HostName').inner_text
end
Also aliased as: ip
informational_events(&block) click to toggle source

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_events do |info|
  puts info.port
  puts info.data if info.data
end
# File lib/ruby-nessus/version1/host.rb, line 124
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_events << Event.new(event)
      @informational_event_count += 1
    end

  end

  @informational_events.each(&block)
  @informational_event_count
end
ip()
Alias for: hostname
low_severity_events(&block) click to toggle source

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.

@yieldparam [EVENT] prog The newly created Event object. @return [Integer]

Return The Low Event Count For A Given Host.

@example

host.low_severity_events do |low|
  puts low.name if low.name
end
# File lib/ruby-nessus/version1/host.rb, line 151
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

  end

  @low_severity_events.each(&block)
  @low_severity_count
end
mac_addr() click to toggle source

Return the Host Mac Address. @return [String]

Return the Host Mac Address

@example

host.mac_addr #=> "00:11:22:33:44:55"
# File lib/ruby-nessus/version1/host.rb, line 80
def mac_addr
  @mac_addr ||= @host.at('mac_addr').inner_text
end
Also aliased as: mac_address
mac_address()
Alias for: mac_addr
medium_severity_events(&block) click to toggle source

Returns All Medium 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 Medium Event Count For A Given Host.

@example

host.medium_severity_events do |medium|
  puts medium.name if medium.name
end
# File lib/ruby-nessus/version1/host.rb, line 178
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

  end

  @medium_severity_events.each(&block)
  @high_severity_count
end
netbios_name() click to toggle source

Return the Host Netbios Name. @return [String]

The Host Netbios Name

@example

host.netbios_name #=> "SOMENAME4243"
# File lib/ruby-nessus/version1/host.rb, line 71
def netbios_name
  @netbios_name ||= @host.at('netbios_name').inner_text
end
open_ports() click to toggle source

Return the open ports for a given host object. @return [Integer]

Return the open ports for a given host object.

@example

host.open_ports #=> 213
# File lib/ruby-nessus/version1/host.rb, line 109
def open_ports
  @scanned_ports ||= @host.at('num_ports').inner_text.to_i
end
operating_system()
Alias for: os_name
os_name() click to toggle source

Return the Host OS Name. @return [String]

Return the Host OS Name

@example

host.dns_name #=> "Microsoft Windows 2000, Microsoft Windows Server 2003"
# File lib/ruby-nessus/version1/host.rb, line 99
def os_name
  @os_name ||= @host.at('os_name').inner_text
end
Also aliased as: operating_system
runtime()
Alias for: scan_runtime
scan_runtime() click to toggle source

Return the host run time. @return [String]

The Host Scan Run Time

@example

scan.scan_run_time #=> '2 hours 5 minutes and 16 seconds'
# File lib/ruby-nessus/version1/host.rb, line 61
def scan_runtime
  get_runtime
end
Also aliased as: runtime
scan_start_time() click to toggle source

Return the host scan start time. @return [DateTime]

The Host Scan Start Time

@example

scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985'
# File lib/ruby-nessus/version1/host.rb, line 35
def scan_start_time
  if @host.at('startTime').inner_text.empty?
    false
  else
    @host_scan_time = DateTime.strptime(@host.at('startTime').inner_text, '%a %b %d %H:%M:%S %Y')
  end
end
scan_stop_time() click to toggle source

Return the host scan stop time. @return [DateTime]

The Host Scan Stop Time

@example

scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985'
# File lib/ruby-nessus/version1/host.rb, line 48
def scan_stop_time
  if @host.at('stopTime').inner_text.empty?
    false
  else
    @host_scan_time = DateTime.strptime(@host.at('stopTime').inner_text, '%a %b %d %H:%M:%S %Y')
  end
end
to_s() click to toggle source
# File lib/ruby-nessus/version1/host.rb, line 16
def to_s
  ip.to_s
end

Private Instance Methods

get_runtime() click to toggle source
# File lib/ruby-nessus/version1/host.rb, line 255
def get_runtime
  if scan_start_time && scan_stop_time
    h = (Time.parse(scan_stop_time.to_s).strftime('%H').to_i - Time.parse(scan_start_time.to_s).strftime('%H').to_i).to_s.delete('-')
    m = (Time.parse(scan_stop_time.to_s).strftime('%M').to_i - Time.parse(scan_start_time.to_s).strftime('%M').to_i).to_s.delete('-')
    s = (Time.parse(scan_stop_time.to_s).strftime('%S').to_i - Time.parse(scan_start_time.to_s).strftime('%S').to_i).to_s.delete('-')
    "#{h} hours #{m} minutes and #{s} seconds"
  else
    false
  end
end