Class: Nmap::XML::Host
- Inherits:
-
Object
- Object
- Nmap::XML::Host
- Includes:
- Enumerable
- Defined in:
- lib/nmap/xml/host.rb
Overview
Wraps a host
XML element.
Instance Method Summary collapse
-
#address ⇒ String
The address of the host.
-
#addresses ⇒ Array<Host>
Parses the addresses of the host.
-
#each(&block) ⇒ Object
Parses the open ports of the host.
-
#each_address {|addr| ... } ⇒ Host, Enumerator
Parses each address of the host.
-
#each_hostname {|host| ... } ⇒ Host, Enumerator
Parses the hostnames of the host.
-
#each_open_port {|port| ... } ⇒ Host, Enumerator
Parses the open ports of the host.
-
#each_port {|port| ... } ⇒ Host, Enumerator
Parses the scanned ports of the host.
-
#each_tcp_port {|port| ... } ⇒ Host, Enumerator
Parses the TCP ports of the host.
-
#each_udp_port {|port| ... } ⇒ Host, Enumerator
Parses the UDP ports of the host.
-
#end_time ⇒ Time
The time the host was last scanned.
-
#host_script ⇒ HostScript?
The NSE scripts ran against the host.
-
#hostname ⇒ Hostname?
The primary hostname of the host.
-
#hostnames ⇒ Array<Hostname>
Parses the hostnames of the host.
-
#initialize(node) ⇒ Host
constructor
Creates a new Host object.
-
#inspect ⇒ String
Inspects the host.
-
#ip ⇒ String
The IP address of the host.
-
#ip_id_sequence {|ipidsequence| ... } ⇒ IpIdSequence
Parses the IPID sequence number analysis of the host.
-
#ipv4 ⇒ String
Parses the IPv4 address of the host.
-
#ipv6 ⇒ String
Parses the IPv6 address of the host.
-
#mac ⇒ String
Parses the MAC address of the host.
-
#open_ports ⇒ Array<Port>
Parses the open ports of the host.
-
#os {|os| ... } ⇒ OS
Parses the OS guessing information of the host.
-
#ports ⇒ Array<Port>
Parses the scanned ports of the host.
-
#start_time ⇒ Time
The time the host was first scanned.
-
#status ⇒ Status
Parses the status of the host.
-
#tcp_ports ⇒ Array<Port>
Parses the TCP ports of the host.
-
#tcp_sequence {|sequence| ... } ⇒ TcpSequence
Parses the TCP Sequence number analysis of the host.
-
#tcp_ts_sequence {|tcptssequence| ... } ⇒ TcpTsSequence
Parses the TCP Timestamp sequence number analysis of the host.
-
#to_s ⇒ String
Converts the host to a String.
-
#traceroute {|traceroute| ... } ⇒ Traceroute
Parses the traceroute information, if present.
-
#udp_ports ⇒ Array<Port>
Parses the UDP ports of the host.
-
#uptime {|uptime| ... } ⇒ Uptime
Parses the Uptime analysis of the host.
-
#vendor ⇒ String
Parses the MAC vendor of the host.
Constructor Details
#initialize(node) ⇒ Host
Creates a new Host object.
35 36 37 |
# File 'lib/nmap/xml/host.rb', line 35 def initialize(node) @node = node end |
Instance Method Details
#address ⇒ String
The address of the host.
188 189 190 |
# File 'lib/nmap/xml/host.rb', line 188 def address ip || mac end |
#addresses ⇒ Array<Host>
Parses the addresses of the host.
118 119 120 |
# File 'lib/nmap/xml/host.rb', line 118 def addresses each_address.to_a end |
#each(&block) ⇒ Object
Parses the open ports of the host.
483 484 485 |
# File 'lib/nmap/xml/host.rb', line 483 def each(&block) each_open_port(&block) end |
#each_address {|addr| ... } ⇒ Host, Enumerator
Parses each address of the host.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/nmap/xml/host.rb', line 96 def each_address return enum_for(__method__) unless block_given? @node.xpath("address[@addr]").each do |addr| address = Address.new( addr['addrtype'].to_sym, addr['addr'], addr['vendor'] ) yield address end return self end |
#each_hostname {|host| ... } ⇒ Host, Enumerator
Parses the hostnames of the host.
205 206 207 208 209 210 211 212 213 |
# File 'lib/nmap/xml/host.rb', line 205 def each_hostname return enum_for(__method__) unless block_given? @node.xpath("hostnames/hostname[@name]").each do |host| yield Hostname.new(host['type'],host['name']) end return self end |
#each_open_port {|port| ... } ⇒ Host, Enumerator
Parses the open ports of the host.
392 393 394 395 396 397 398 399 400 |
# File 'lib/nmap/xml/host.rb', line 392 def each_open_port return enum_for(__method__) unless block_given? @node.xpath("ports/port[state/@state='open']").each do |port| yield Port.new(port) end return self end |
#each_port {|port| ... } ⇒ Host, Enumerator
Parses the scanned ports of the host.
359 360 361 362 363 364 365 366 367 |
# File 'lib/nmap/xml/host.rb', line 359 def each_port return enum_for(__method__) unless block_given? @node.xpath("ports/port").each do |port| yield Port.new(port) end return self end |
#each_tcp_port {|port| ... } ⇒ Host, Enumerator
Parses the TCP ports of the host.
425 426 427 428 429 430 431 432 433 |
# File 'lib/nmap/xml/host.rb', line 425 def each_tcp_port return enum_for(__method__) unless block_given? @node.xpath("ports/port[@protocol='tcp']").each do |port| yield Port.new(port) end return self end |
#each_udp_port {|port| ... } ⇒ Host, Enumerator
Parses the UDP ports of the host.
458 459 460 461 462 463 464 465 466 |
# File 'lib/nmap/xml/host.rb', line 458 def each_udp_port return enum_for(__method__) unless block_given? @node.xpath("ports/port[@protocol='udp']").each do |port| yield Port.new(port) end return self end |
#end_time ⇒ Time
The time the host was last scanned.
59 60 61 |
# File 'lib/nmap/xml/host.rb', line 59 def end_time @end_time ||= Time.at(@node['endtime'].to_i) end |
#host_script ⇒ HostScript?
The NSE scripts ran against the host.
495 496 497 498 499 |
# File 'lib/nmap/xml/host.rb', line 495 def host_script @host_script ||= if (hostscript = @node.at_xpath('hostscript')) HostScript.new(hostscript) end end |
#hostname ⇒ Hostname?
The primary hostname of the host.
232 233 234 |
# File 'lib/nmap/xml/host.rb', line 232 def hostname each_hostname.first end |
#hostnames ⇒ Array<Hostname>
Parses the hostnames of the host.
221 222 223 |
# File 'lib/nmap/xml/host.rb', line 221 def hostnames each_hostname.to_a end |
#inspect ⇒ String
Inspects the host.
542 543 544 |
# File 'lib/nmap/xml/host.rb', line 542 def inspect "#<#{self.class}: #{self}>" end |
#ip ⇒ String
The IP address of the host.
178 179 180 |
# File 'lib/nmap/xml/host.rb', line 178 def ip ipv6 || ipv4 end |
#ip_id_sequence {|ipidsequence| ... } ⇒ IpIdSequence
Parses the IPID sequence number analysis of the host.
316 317 318 319 320 321 322 323 |
# File 'lib/nmap/xml/host.rb', line 316 def ip_id_sequence @ip_id_sequence ||= if (seq = @node.at_xpath('ipidsequence')) IpIdSequence.new(seq) end yield @ip_id_sequence if (@ip_id_sequence && block_given?) return @ip_id_sequence end |
#ipv4 ⇒ String
Parses the IPv4 address of the host.
154 155 156 157 158 |
# File 'lib/nmap/xml/host.rb', line 154 def ipv4 @ipv4 ||= if (addr = @node.at_xpath("address[@addrtype='ipv4']")) addr['addr'] end end |
#ipv6 ⇒ String
Parses the IPv6 address of the host.
166 167 168 169 170 |
# File 'lib/nmap/xml/host.rb', line 166 def ipv6 @ipv6 ||= if (addr = @node.at_xpath("address[@addrtype='ipv6']")) addr['addr'] end end |
#mac ⇒ String
Parses the MAC address of the host.
128 129 130 131 132 |
# File 'lib/nmap/xml/host.rb', line 128 def mac @mac ||= if (addr = @node.at_xpath("address[@addrtype='mac']")) addr['addr'] end end |
#open_ports ⇒ Array<Port>
Parses the open ports of the host.
408 409 410 |
# File 'lib/nmap/xml/host.rb', line 408 def open_ports each_open_port.to_a end |
#os {|os| ... } ⇒ OS
Parses the OS guessing information of the host.
248 249 250 251 252 253 254 255 |
# File 'lib/nmap/xml/host.rb', line 248 def os @os ||= if (os = @node.at_xpath('os')) OS.new(os) end yield @os if (@os && block_given?) return @os end |
#ports ⇒ Array<Port>
Parses the scanned ports of the host.
375 376 377 |
# File 'lib/nmap/xml/host.rb', line 375 def ports each_port.to_a end |
#start_time ⇒ Time
The time the host was first scanned.
47 48 49 |
# File 'lib/nmap/xml/host.rb', line 47 def start_time @start_time ||= Time.at(@node['starttime'].to_i) end |
#status ⇒ Status
Parses the status of the host.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nmap/xml/host.rb', line 69 def status unless @status status = @node.at_xpath('status') @status = Status.new( status['state'].to_sym, status['reason'], status['reason_ttl'].to_i ) end return @status end |
#tcp_ports ⇒ Array<Port>
Parses the TCP ports of the host.
441 442 443 |
# File 'lib/nmap/xml/host.rb', line 441 def tcp_ports each_tcp_port.to_a end |
#tcp_sequence {|sequence| ... } ⇒ TcpSequence
Parses the TCP Sequence number analysis of the host.
295 296 297 298 299 300 301 302 |
# File 'lib/nmap/xml/host.rb', line 295 def tcp_sequence @tcp_sequence ||= if (seq = @node.at_xpath('tcpsequence')) TcpSequence.new(seq) end yield @tcp_sequence if (@tcp_sequence && block_given?) return @tcp_sequence end |
#tcp_ts_sequence {|tcptssequence| ... } ⇒ TcpTsSequence
Parses the TCP Timestamp sequence number analysis of the host.
337 338 339 340 341 342 343 344 |
# File 'lib/nmap/xml/host.rb', line 337 def tcp_ts_sequence @tcp_ts_sequence ||= if (seq = @node.at_xpath('tcptssequence')) TcpTsSequence.new(seq) end yield @tcp_ts_sequence if (@tcp_ts_sequence && block_given?) return @tcp_ts_sequence end |
#to_s ⇒ String
Converts the host to a String.
532 533 534 |
# File 'lib/nmap/xml/host.rb', line 532 def to_s (hostname || address).to_s end |
#traceroute {|traceroute| ... } ⇒ Traceroute
Parses the traceroute information, if present.
515 516 517 518 519 520 521 522 |
# File 'lib/nmap/xml/host.rb', line 515 def traceroute @traceroute ||= if (trace = @node.at_xpath('trace')) Traceroute.new(trace) end yield @traceroute if (@traceroute && block_given?) return @traceroute end |
#udp_ports ⇒ Array<Port>
Parses the UDP ports of the host.
474 475 476 |
# File 'lib/nmap/xml/host.rb', line 474 def udp_ports each_udp_port.to_a end |
#uptime {|uptime| ... } ⇒ Uptime
Parses the Uptime analysis of the host.
271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/nmap/xml/host.rb', line 271 def uptime @uptime ||= if (uptime = @node.at_xpath('uptime')) Uptime.new( uptime['seconds'].to_i, Time.parse(uptime['lastboot']) ) end yield @uptime if (@uptime && block_given?) return @uptime end |
#vendor ⇒ String
Parses the MAC vendor of the host.
142 143 144 145 146 |
# File 'lib/nmap/xml/host.rb', line 142 def vendor @vendor ||= if (vendor = @node.at_xpath("address/@vendor")) vendor.inner_text end end |