Class: Nmap::Host
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.
-
#ipidsequence(&block) ⇒ Object
deprecated
Deprecated.
Use #ip_id_sequence instead.
-
#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.
-
#scripts ⇒ Hash{String => String}
deprecated
Deprecated.
Use #host_script instead.
-
#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.
-
#tcpsequence(&block) ⇒ Object
deprecated
Deprecated.
Use #tcp_sequence instead.
-
#tcptssequence(&block) ⇒ Object
deprecated
Deprecated.
Use #tcp_ts_sequence instead.
-
#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.
30 31 32 |
# File 'lib/nmap/host.rb', line 30 def initialize(node) @node = node end |
Instance Method Details
#address ⇒ String
The address of the host.
182 183 184 |
# File 'lib/nmap/host.rb', line 182 def address ip || mac end |
#addresses ⇒ Array<Host>
Parses the addresses of the host.
112 113 114 |
# File 'lib/nmap/host.rb', line 112 def addresses each_address.to_a end |
#each(&block) ⇒ Object
Parses the open ports of the host.
504 505 506 |
# File 'lib/nmap/host.rb', line 504 def each(&block) each_open_port(&block) end |
#each_address {|addr| ... } ⇒ Host, Enumerator
Parses each address of the host.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nmap/host.rb', line 90 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.
199 200 201 202 203 204 205 206 207 |
# File 'lib/nmap/host.rb', line 199 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.
413 414 415 416 417 418 419 420 421 |
# File 'lib/nmap/host.rb', line 413 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.
380 381 382 383 384 385 386 387 388 |
# File 'lib/nmap/host.rb', line 380 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.
446 447 448 449 450 451 452 453 454 |
# File 'lib/nmap/host.rb', line 446 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.
479 480 481 482 483 484 485 486 487 |
# File 'lib/nmap/host.rb', line 479 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.
54 55 56 |
# File 'lib/nmap/host.rb', line 54 def end_time @end_time ||= Time.at(@node['endtime'].to_i) end |
#host_script ⇒ HostScript?
The NSE scripts ran against the host.
534 535 536 537 538 |
# File 'lib/nmap/host.rb', line 534 def host_script @host_script ||= if (hostscript = @node.at_xpath('hostscript')) HostScript.new(hostscript) end end |
#hostname ⇒ Hostname?
The primary hostname of the host.
226 227 228 |
# File 'lib/nmap/host.rb', line 226 def hostname each_hostname.first end |
#hostnames ⇒ Array<Hostname>
Parses the hostnames of the host.
215 216 217 |
# File 'lib/nmap/host.rb', line 215 def hostnames each_hostname.to_a end |
#inspect ⇒ String
Inspects the host.
581 582 583 |
# File 'lib/nmap/host.rb', line 581 def inspect "#<#{self.class}: #{self}>" end |
#ip ⇒ String
The IP address of the host.
172 173 174 |
# File 'lib/nmap/host.rb', line 172 def ip ipv6 || ipv4 end |
#ip_id_sequence {|ipidsequence| ... } ⇒ IpIdSequence
Parses the IPID sequence number analysis of the host.
319 320 321 322 323 324 325 326 |
# File 'lib/nmap/host.rb', line 319 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 |
#ipidsequence(&block) ⇒ Object
Use #ip_id_sequence instead.
331 332 333 334 335 |
# File 'lib/nmap/host.rb', line 331 def ipidsequence(&block) warn "DEPRECATION: use #{self.class}#ip_id_sequence instead" ip_id_sequence(&block) end |
#ipv4 ⇒ String
Parses the IPv4 address of the host.
148 149 150 151 152 |
# File 'lib/nmap/host.rb', line 148 def ipv4 @ipv4 ||= if (addr = @node.at_xpath("address[@addrtype='ipv4']")) addr['addr'] end end |
#ipv6 ⇒ String
Parses the IPv6 address of the host.
160 161 162 163 164 |
# File 'lib/nmap/host.rb', line 160 def ipv6 @ipv6 ||= if (addr = @node.at_xpath("address[@addrtype='ipv6']")) addr['addr'] end end |
#mac ⇒ String
Parses the MAC address of the host.
122 123 124 125 126 |
# File 'lib/nmap/host.rb', line 122 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.
429 430 431 |
# File 'lib/nmap/host.rb', line 429 def open_ports each_open_port.to_a end |
#os {|os| ... } ⇒ OS
Parses the OS guessing information of the host.
242 243 244 245 246 247 248 249 |
# File 'lib/nmap/host.rb', line 242 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.
396 397 398 |
# File 'lib/nmap/host.rb', line 396 def ports each_port.to_a end |
#scripts ⇒ Hash{String => String}
Use #host_script instead.
The output from the NSE scripts ran against the host.
518 519 520 521 522 523 524 |
# File 'lib/nmap/host.rb', line 518 def scripts if host_script host_script.scripts else {} end end |
#start_time ⇒ Time
The time the host was first scanned.
42 43 44 |
# File 'lib/nmap/host.rb', line 42 def start_time @start_time ||= Time.at(@node['starttime'].to_i) end |
#status ⇒ Status
Parses the status of the host.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nmap/host.rb', line 64 def status unless @status status = @node.at_xpath('status') @status = Status.new( status['state'].to_sym, status['reason'] ) end return @status end |
#tcp_ports ⇒ Array<Port>
Parses the TCP ports of the host.
462 463 464 |
# File 'lib/nmap/host.rb', line 462 def tcp_ports each_tcp_port.to_a end |
#tcp_sequence {|sequence| ... } ⇒ TcpSequence
Parses the Tcp Sequence number analysis of the host.
289 290 291 292 293 294 295 296 |
# File 'lib/nmap/host.rb', line 289 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.
349 350 351 352 353 354 355 356 |
# File 'lib/nmap/host.rb', line 349 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 |
#tcpsequence(&block) ⇒ Object
Use #tcp_sequence instead.
301 302 303 304 305 |
# File 'lib/nmap/host.rb', line 301 def tcpsequence(&block) warn "DEPRECATION: use #{self.class}#tcp_sequence instead" tcp_sequence(&block) end |
#tcptssequence(&block) ⇒ Object
Use #tcp_ts_sequence instead.
361 362 363 364 365 |
# File 'lib/nmap/host.rb', line 361 def tcptssequence(&block) warn "DEPRECATION: use #{self.class}#tcp_ts_sequence instead" tcp_ts_sequence(&block) end |
#to_s ⇒ String
Converts the host to a String.
571 572 573 |
# File 'lib/nmap/host.rb', line 571 def to_s (hostname || address).to_s end |
#traceroute {|traceroute| ... } ⇒ Traceroute
Parses the traceroute information, if present.
554 555 556 557 558 559 560 561 |
# File 'lib/nmap/host.rb', line 554 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.
495 496 497 |
# File 'lib/nmap/host.rb', line 495 def udp_ports each_udp_port.to_a end |
#uptime {|uptime| ... } ⇒ Uptime
Parses the Uptime analysis of the host.
265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/nmap/host.rb', line 265 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.
136 137 138 139 140 |
# File 'lib/nmap/host.rb', line 136 def vendor @vendor ||= if (vendor = @node.at_xpath("address/@vendor")) vendor.inner_text end end |