Class: Nessus::Version2::Host
- Inherits:
-
Object
- Object
- Nessus::Version2::Host
- Includes:
- Enumerable
- Defined in:
- lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb
Instance Method Summary collapse
-
#critical_severity_count ⇒ Integer
Return the Critical severity count.
-
#critical_severity_events {|prog| ... } ⇒ Integer
Returns All Critical Event Objects For A Given Host.
-
#each_event {|prog| ... } ⇒ Object
Creates a new Event object to be parser.
-
#event_count ⇒ Integer
Return the total event count for a given host.
-
#event_percentage_for(type, round_percentage = false) ⇒ Integer
Return the Total severity count.
-
#events ⇒ Array<String>
Parses the events of the host.
-
#high_severity_count ⇒ Integer
Return the High severity count.
-
#high_severity_events {|prog| ... } ⇒ Integer
Returns All High Event Objects For A Given Host.
-
#hostname ⇒ String
(also: #name, #fqdn, #dns_name)
Return the Host Object hostname.
-
#icmp_count ⇒ Integer
Return the ICMP Event Count.
-
#informational_severity_count ⇒ Integer
Return the informational severity count.
-
#informational_severity_events {|prog| ... } ⇒ Integer
Returns All Informational Event Objects For A Given Host.
-
#initialize(host) ⇒ Host
constructor
Creates A New Host Object.
-
#ip ⇒ String
Return the Host Object IP.
-
#low_severity_count ⇒ Integer
Return the Low severity count.
-
#low_severity_events {|prog| ... } ⇒ Integer
Returns All Low Event Objects For A Given Host.
-
#mac_addr ⇒ String
(also: #mac_address)
Return the Host Mac Address.
- #medium_severity ⇒ Object
-
#medium_severity_count ⇒ Integer
Return the Medium severity count.
-
#medium_severity_events {|prog| ... } ⇒ Integer
Returns All Medium Event Objects For A Given Host.
-
#netbios_name ⇒ String
Return the Host Netbios Name.
-
#open_ports ⇒ Integer
Return the open ports for a given host object.
-
#os_name ⇒ String
(also: #os, #operating_system)
Return the Host OS Name.
-
#ports ⇒ Array
Return the Open Ports count.
-
#runtime ⇒ String
(also: #scan_runtime)
Return the host run time.
-
#start_time ⇒ DateTime
Return the host scan start time.
-
#stop_time ⇒ DateTime
Return the host scan stop time.
-
#tcp_count ⇒ Integer
Return the TCP Event Count.
- #to_s ⇒ Object
-
#total_event_count(count_informational = false) ⇒ Integer
Return the Total severity count.
-
#udp_count ⇒ Integer
Return the UDP Event Count.
Constructor Details
#initialize(host) ⇒ Host
Creates A New Host Object
Host.new(object)
15 16 17 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 15 def initialize(host) @host = host end |
Instance Method Details
#critical_severity_count ⇒ Integer
Return the Critical severity count.
447 448 449 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 447 def critical_severity_count host_stats[:critical].to_i end |
#critical_severity_events {|prog| ... } ⇒ Integer
Returns All Critical Event Objects For A Given Host.
308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 308 def critical_severity_events(&block) unless @critical_severity_events @critical_severity_events = [] @host.xpath("ReportItem").each do |event| next if event['severity'].to_i != 4 @critical_severity_events << Event.new(event) end end @critical_severity_events.each(&block) end |
#each_event {|prog| ... } ⇒ Object
Creates a new Event object to be parser
349 350 351 352 353 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 349 def each_event(&block) @host.xpath("ReportItem").each do |event| block.call(Event.new(event)) if block end end |
#event_count ⇒ Integer
Return the total event count for a given host.
332 333 334 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 332 def event_count ((low_severity_events.to_i) + (medium_severity_events.to_i) + (high_severity_events.to_i) + (critical_severity_events.to_i)).to_i end |
#event_percentage_for(type, round_percentage = false) ⇒ Integer
Return the Total severity count.
522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 522 def event_percentage_for(type, round_percentage=false) @sc ||= host_stats if %W(high medium low tcp udp icmp all).include?(type) calc = ((@sc[:"#{type}"].to_f / (@sc[:all].to_f)) * 100) if round_percentage return "#{calc.round}" else return "#{calc}" end else raise "Error: #{type} is not an acceptable severity. Possible options include: all, tdp, udp, icmp, high, medium and low." end end |
#events ⇒ Array<String>
Parses the events of the host.
361 362 363 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 361 def events Enumerator.new(self,:each_event).to_a end |
#high_severity_count ⇒ Integer
Return the High severity count.
460 461 462 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 460 def high_severity_count host_stats[:high].to_i end |
#high_severity_events {|prog| ... } ⇒ Integer
Returns All High Event Objects For A Given Host.
277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 277 def high_severity_events(&block) unless @high_severity_events @high_severity_events = [] @host.xpath("ReportItem").each do |event| next if event['severity'].to_i != 3 @high_severity_events << Event.new(event) end end @high_severity_events.each(&block) end |
#hostname ⇒ String Also known as: name, fqdn, dns_name
Return the Host Object hostname.
32 33 34 35 36 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 32 def hostname if (host = @host.at('tag[name=host-fqdn]')) host.inner_text end end |
#icmp_count ⇒ Integer
Return the ICMP Event Count.
421 422 423 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 421 def icmp_count host_stats[:icmp].to_i end |
#informational_severity_count ⇒ Integer
Return the informational severity count.
434 435 436 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 434 def informational_severity_count host_stats[:informational].to_i end |
#informational_severity_events {|prog| ... } ⇒ Integer
Returns All Informational Event Objects For A Given Host.
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 182 def informational_severity_events(&block) unless @informational_events @informational_events = [] @host.xpath("ReportItem").each do |event| next if event['severity'].to_i != 0 @informational_events << Event.new(event) end end @informational_events.each(&block) end |
#ip ⇒ String
Return the Host Object IP.
50 51 52 53 54 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 50 def ip if (ip = @host.at('tag[name=host-ip]')) ip.inner_text end end |
#low_severity_count ⇒ Integer
Return the Low severity count.
486 487 488 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 486 def low_severity_count host_stats[:low].to_i end |
#low_severity_events {|prog| ... } ⇒ Integer
Returns All Low Event Objects For A Given Host.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 212 def low_severity_events(&block) unless @low_severity_events @low_severity_events = [] @host.xpath("ReportItem").each do |event| next if event['severity'].to_i != 1 @low_severity_events << Event.new(event) end end @low_severity_events.each(&block) end |
#mac_addr ⇒ String Also known as: mac_address
Return the Host Mac Address.
128 129 130 131 132 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 128 def mac_addr if (mac_addr = @host.at('tag[name=mac-addr]')) mac_addr.inner_text end end |
#medium_severity ⇒ Object
257 258 259 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 257 def medium_severity Enumerator.new(self,:medium_severity_events).to_a end |
#medium_severity_count ⇒ Integer
Return the Medium severity count.
473 474 475 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 473 def medium_severity_count host_stats[:medium].to_i end |
#medium_severity_events {|prog| ... } ⇒ Integer
Returns All Medium Event Objects For A Given Host.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 242 def medium_severity_events(&block) unless @medium_severity_events @medium_severity_events = [] @host.xpath("ReportItem").each do |event| next if event['severity'].to_i != 2 @medium_severity_events << Event.new(event) end end @medium_severity_events.each(&block) end |
#netbios_name ⇒ String
Return the Host Netbios Name.
113 114 115 116 117 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 113 def netbios_name if (netbios = @host.at('tag[name=netbios-name]')) netbios.inner_text end end |
#open_ports ⇒ Integer
Return the open ports for a given host object.
161 162 163 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 161 def open_ports @scanned_ports ||= host_stats[:open_ports].to_i end |
#os_name ⇒ String Also known as: os, operating_system
Return the Host OS Name.
144 145 146 147 148 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 144 def os_name if (os_name = @host.at('tag[name=operating-system]')) os_name.inner_text end end |
#ports ⇒ Array
Return the Open Ports count.
374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 374 def ports unless @ports @ports = [] @host.xpath("ReportItem").each do |port| @ports << port['port'] end @ports.uniq! @ports.sort! end @ports end |
#runtime ⇒ String Also known as: scan_runtime
Return the host run time.
99 100 101 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 99 def runtime get_runtime end |
#start_time ⇒ DateTime
Return the host scan start time.
65 66 67 68 69 70 71 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 65 def start_time if (start_time = @host.at('tag[name=HOST_START]')) DateTime.strptime(start_time.inner_text, fmt='%a %b %d %H:%M:%S %Y') else false end end |
#stop_time ⇒ DateTime
Return the host scan stop time.
82 83 84 85 86 87 88 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 82 def stop_time if (stop_time = @host.at('tag[name=HOST_END]')) DateTime.strptime(stop_time.inner_text, fmt='%a %b %d %H:%M:%S %Y') else false end end |
#tcp_count ⇒ Integer
Return the TCP Event Count.
395 396 397 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 395 def tcp_count host_stats[:tcp].to_i end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 19 def to_s "#{ip}" end |
#total_event_count(count_informational = false) ⇒ Integer
Return the Total severity count. [high, medium, low, informational]
499 500 501 502 503 504 505 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 499 def total_event_count(count_informational = false) if count_informational host_stats[:all].to_i + informational_severity_count else host_stats[:all].to_i end end |
#udp_count ⇒ Integer
Return the UDP Event Count.
408 409 410 |
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version2/host.rb', line 408 def udp_count host_stats[:udp].to_i end |