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.
-
#hostnames ⇒ Array<String>
Parses the hostnames of the host.
-
#initialize(node) {|host| ... } ⇒ Host
constructor
Creates a new Host object.
-
#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}
The output from the NSE scripts ran against 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.
-
#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.
-
#udp_ports ⇒ Array<Port>
Parses the UDP ports of the host.
Constructor Details
#initialize(node) {|host| ... } ⇒ Host
Creates a new Host object.
32 33 34 35 36 |
# File 'lib/nmap/host.rb', line 32 def initialize(node) @node = node yield self if block_given? end |
Instance Method Details
#address ⇒ String
The address of the host.
171 172 173 |
# File 'lib/nmap/host.rb', line 171 def address ip || mac end |
#addresses ⇒ Array<Host>
Parses the addresses of the host.
115 116 117 |
# File 'lib/nmap/host.rb', line 115 def addresses each_address.to_a end |
#each(&block) ⇒ Object
Parses the open ports of the host.
456 457 458 |
# File 'lib/nmap/host.rb', line 456 def each(&block) each_open_port(&block) end |
#each_address {|addr| ... } ⇒ Host, Enumerator
Parses each address of the host.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/nmap/host.rb', line 94 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'] ) yield address end return self end |
#each_hostname {|host| ... } ⇒ Host, Enumerator
Parses the hostnames of the host.
188 189 190 191 192 193 194 195 196 |
# File 'lib/nmap/host.rb', line 188 def each_hostname return enum_for(__method__) unless block_given? @node.xpath("hostnames/hostname[@name]").each do |host| yield host['name'] end return self end |
#each_open_port {|port| ... } ⇒ Host, Enumerator
Parses the open ports of the host.
365 366 367 368 369 370 371 372 373 |
# File 'lib/nmap/host.rb', line 365 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.
332 333 334 335 336 337 338 339 340 |
# File 'lib/nmap/host.rb', line 332 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.
398 399 400 401 402 403 404 405 406 |
# File 'lib/nmap/host.rb', line 398 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.
431 432 433 434 435 436 437 438 439 |
# File 'lib/nmap/host.rb', line 431 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.
58 59 60 |
# File 'lib/nmap/host.rb', line 58 def end_time @end_time ||= Time.at(@node['endtime'].to_i) end |
#hostnames ⇒ Array<String>
Parses the hostnames of the host.
204 205 206 |
# File 'lib/nmap/host.rb', line 204 def hostnames each_hostname.to_a end |
#ip ⇒ String
The IP address of the host.
161 162 163 |
# File 'lib/nmap/host.rb', line 161 def ip ipv6 || ipv4 end |
#ip_id_sequence {|ipidsequence| ... } ⇒ IpIdSequence
Parses the IPID sequence number analysis of the host.
271 272 273 274 275 276 277 278 |
# File 'lib/nmap/host.rb', line 271 def ip_id_sequence @ip_id_sequence ||= if (seq = @node.at('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.
283 284 285 286 287 |
# File 'lib/nmap/host.rb', line 283 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.
137 138 139 140 141 |
# File 'lib/nmap/host.rb', line 137 def ipv4 @ipv4 ||= if (addr = @node.xpath("address[@addrtype='ipv4']").first) addr['addr'] end end |
#ipv6 ⇒ String
Parses the IPv6 address of the host.
149 150 151 152 153 |
# File 'lib/nmap/host.rb', line 149 def ipv6 @ipv6 ||= if (@node.xpath("address[@addrtype='ipv6']").first) addr['addr'] end end |
#mac ⇒ String
Parses the MAC address of the host.
125 126 127 128 129 |
# File 'lib/nmap/host.rb', line 125 def mac @mac ||= if (addr = @node.xpath("address[@addrtype='mac']").first) addr['addr'] end end |
#open_ports ⇒ Array<Port>
Parses the open ports of the host.
381 382 383 |
# File 'lib/nmap/host.rb', line 381 def open_ports each_open_port.to_a end |
#os {|os| ... } ⇒ OS
Parses the OS guessing information of the host.
220 221 222 223 224 225 226 227 |
# File 'lib/nmap/host.rb', line 220 def os @os ||= if (os = @node.at('os')) OS.new(os) end yield @os if (@os && block_given?) return @os end |
#ports ⇒ Array<Port>
Parses the scanned ports of the host.
348 349 350 |
# File 'lib/nmap/host.rb', line 348 def ports each_port.to_a end |
#scripts ⇒ Hash{String => String}
The output from the NSE scripts ran against the host.
468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/nmap/host.rb', line 468 def scripts unless @scripts @scripts = {} @node.xpath('hostscript/script').each do |script| @scripts[script['id']] = script['output'] end end return @scripts end |
#start_time ⇒ Time
The time the host was first scanned.
46 47 48 |
# File 'lib/nmap/host.rb', line 46 def start_time @start_time ||= Time.at(@node['starttime'].to_i) end |
#status ⇒ Status
Parses the status of the host.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nmap/host.rb', line 68 def status unless @status status = @node.at('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.
414 415 416 |
# File 'lib/nmap/host.rb', line 414 def tcp_ports each_tcp_port.to_a end |
#tcp_sequence {|sequence| ... } ⇒ TcpSequence
Parses the Tcp Sequence number analysis of the host.
241 242 243 244 245 246 247 248 |
# File 'lib/nmap/host.rb', line 241 def tcp_sequence @tcp_sequence ||= if (seq = @node.at('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.
301 302 303 304 305 306 307 308 |
# File 'lib/nmap/host.rb', line 301 def tcp_ts_sequence @tcp_ts_sequence ||= if (seq = @node.at('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.
253 254 255 256 257 |
# File 'lib/nmap/host.rb', line 253 def tcpsequence(&block) warn "DEPRECATION: use #{self.class}#tcp_sequence instead" tcp_sequence(&block) end |
#tcptssequence(&block) ⇒ Object
Use #tcp_ts_sequence instead.
313 314 315 316 317 |
# File 'lib/nmap/host.rb', line 313 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.
488 489 490 |
# File 'lib/nmap/host.rb', line 488 def to_s address.to_s end |
#udp_ports ⇒ Array<Port>
Parses the UDP ports of the host.
447 448 449 |
# File 'lib/nmap/host.rb', line 447 def udp_ports each_udp_port.to_a end |