Class: Nessus::Version1::Host

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Host

Creates A New Host Object Host.new(object)

Parameters:

  • Host (Object)

    Object



11
12
13
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 11

def initialize(host)
  @host = host
end

Instance Method Details

#dns_nameString

Return the Host DNS Name.

Examples:

host.dns_name #=> "snorby.org"

Returns:

  • (String)

    Return the Host DNS Name



89
90
91
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 89

def dns_name
  @dns_name ||= @host.at('dns_name').inner_text
end

#each_event {|prog| ... } ⇒ Object

Creates a new Event object to be parser

Examples:

host.events do |event|
  puts event.name if event.name
  puts event.port
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.



242
243
244
245
246
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 242

def each_event(&block)
  @host.xpath("ReportItem").each do |event|
    block.call(Event.new(event)) if block
  end
end

#event_countInteger

Return the total event count for a given host.

Examples:

host.event_count #=> 3456

Returns:

  • (Integer)

    Return the total event count for a given host.



229
230
231
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 229

def event_count
  ((low_severity_events.to_i) + (medium_severity_events.to_i) + (high_severity_events.to_i)).to_i
end

#eventsArray<String>

Parses the events of the host.

Returns:

  • (Array<String>)

    The events of the host.



251
252
253
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 251

def events
  Enumerator.new(self,:each_event).to_a
end

#high_severity_events {|prog| ... } ⇒ Integer

Returns All High Event Objects For A Given Host.

Examples:

host.high_severity_events do |high|
  puts high.name if high.name
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The High Event Count For A Given Host.



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 206

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)
  return @high_severity_count
end

#hostnameString Also known as: ip

Return the Host Object hostname.

Examples:

host.hostname #=> "127.0.0.1"

Returns:

  • (String)

    The Host Object Hostname



24
25
26
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 24

def hostname
  @hostname ||= @host.at('HostName').inner_text
end

#informational_events {|prog| ... } ⇒ Integer

Returns All Informational Event Objects For A Given Host.

Examples:

host.informational_events do |info|
  puts info.port
  puts info.data if info.data
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The Informational Event Count For A Given Host.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 123

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)
  return @informational_event_count
end

#low_severity_events {|prog| ... } ⇒ Integer

Returns All Low Event Objects For A Given Host.

Examples:

host.low_severity_events do |low|
  puts low.name if low.name
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The Low Event Count For A Given Host.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 150

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)
  return @low_severity_count
end

#mac_addrString Also known as: mac_address

Return the Host Mac Address.

Examples:

host.mac_addr #=> "00:11:22:33:44:55"

Returns:

  • (String)

    Return the Host Mac Address



79
80
81
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 79

def mac_addr
  @mac_addr ||= @host.at('mac_addr').inner_text
end

#medium_severity_events {|prog| ... } ⇒ Integer

Returns All Medium Event Objects For A Given Host.

Examples:

host.medium_severity_events do |medium|
  puts medium.name if medium.name
end

Yields:

  • (prog)

    If a block is given, it will be passed the newly created Event object.

Yield Parameters:

  • prog (EVENT)

    The newly created Event object.

Returns:

  • (Integer)

    Return The Medium Event Count For A Given Host.



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/gemcache/ruby-nessus/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)
  return @high_severity_count
end

#netbios_nameString

Return the Host Netbios Name.

Examples:

host.netbios_name #=> "SOMENAME4243"

Returns:

  • (String)

    The Host Netbios Name



70
71
72
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 70

def netbios_name
  @netbios_name ||= @host.at('netbios_name').inner_text
end

#open_portsInteger

Return the open ports for a given host object.

Examples:

host.open_ports #=> 213

Returns:

  • (Integer)

    Return the open ports for a given host object.



108
109
110
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 108

def open_ports
  @scanned_ports ||= @host.at('num_ports').inner_text.to_i
end

#os_nameString Also known as: operating_system

Return the Host OS Name.

Examples:

host.dns_name #=> "Microsoft Windows 2000, Microsoft Windows Server 2003"

Returns:

  • (String)

    Return the Host OS Name



98
99
100
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 98

def os_name
  @os_name ||= @host.at('os_name').inner_text
end

#scan_runtimeString Also known as: runtime

Return the host run time.

Examples:

scan.scan_run_time #=> '2 hours 5 minutes and 16 seconds'

Returns:

  • (String)

    The Host Scan Run Time



60
61
62
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 60

def scan_runtime
  get_runtime
end

#scan_start_timeDateTime

Return the host scan start time.

Examples:

scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985'

Returns:

  • (DateTime)

    The Host Scan Start Time



34
35
36
37
38
39
40
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 34

def scan_start_time
  if @host.at('startTime').inner_text.blank?
    return false
  else
    @host_scan_time = DateTime.strptime(@host.at('startTime').inner_text, fmt='%a %b %d %H:%M:%S %Y')
  end
end

#scan_stop_timeDateTime

Return the host scan stop time.

Examples:

scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985'

Returns:

  • (DateTime)

    The Host Scan Stop Time



47
48
49
50
51
52
53
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 47

def scan_stop_time
  if @host.at('stopTime').inner_text.blank?
    return false
  else
    @host_scan_time = DateTime.strptime(@host.at('stopTime').inner_text, fmt='%a %b %d %H:%M:%S %Y')
  end
end

#to_sObject



15
16
17
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/host.rb', line 15

def to_s
  "#{ip}"
end