Class: Nmap::Host
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.
-
#ipidsequence {|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.
-
#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.
-
#tcpsequence {|tcpsequence| ... } ⇒ TcpSequence
Parses the Tcp Sequence number analysis of the host.
-
#tcptssequence {|tcptssequence| ... } ⇒ TcpTsSequence
Parses the TCP Timestamp sequence number analysis of the host.
-
#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.
29 30 31 32 33 |
# File 'lib/nmap/host.rb', line 29 def initialize(node) @node = node yield self if block_given? end |
Instance Method Details
#address ⇒ String
The address of the host.
180 181 182 |
# File 'lib/nmap/host.rb', line 180 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.
423 424 425 |
# File 'lib/nmap/host.rb', line 423 def each(&block) each_open_port(&block) end |
#each_address {|addr| ... } ⇒ Host, Enumerator
Parses each address of the host.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nmap/host.rb', line 91 def each_address return enum_for(:each_address) 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.
197 198 199 200 201 202 203 204 205 |
# File 'lib/nmap/host.rb', line 197 def each_hostname return enum_for(:each_hostname) 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.
332 333 334 335 336 337 338 339 340 |
# File 'lib/nmap/host.rb', line 332 def each_open_port(&block) return enum_for(:each_open_port) 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.
299 300 301 302 303 304 305 306 307 |
# File 'lib/nmap/host.rb', line 299 def each_port return enum_for(:each_port) 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.
365 366 367 368 369 370 371 372 373 |
# File 'lib/nmap/host.rb', line 365 def each_tcp_port return enum_for(:each_tcp_port) 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.
398 399 400 401 402 403 404 405 406 |
# File 'lib/nmap/host.rb', line 398 def each_udp_port return enum_for(:each_udp_port) 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.
55 56 57 |
# File 'lib/nmap/host.rb', line 55 def end_time @end_time ||= Time.at(@node['endtime'].to_i) end |
#hostnames ⇒ Array<String>
Parses the hostnames of the host.
213 214 215 |
# File 'lib/nmap/host.rb', line 213 def hostnames each_hostname.to_a end |
#ip ⇒ String
The IP address of the host.
170 171 172 |
# File 'lib/nmap/host.rb', line 170 def ip ipv6 || ipv4 end |
#ipidsequence {|ipidsequence| ... } ⇒ IpidSequence
Parses the IPID sequence number analysis of the host.
263 264 265 266 267 |
# File 'lib/nmap/host.rb', line 263 def ipidsequence(&block) if (seq = @node.at('ipidsequence')) @ipidsequence = IpidSequence.new(seq,&block) end end |
#ipv4 ⇒ String
Parses the IPv4 address of the host.
138 139 140 141 142 143 144 145 146 |
# File 'lib/nmap/host.rb', line 138 def ipv4 unless @ipv4 addr = @node.xpath("address[@addr][@addrtype='ipv4']").first @ipv4 = addr['addr'] if addr end return @ipv4 end |
#ipv6 ⇒ String
Parses the IPv6 address of the host.
154 155 156 157 158 159 160 161 162 |
# File 'lib/nmap/host.rb', line 154 def ipv6 unless @ipv6 addr = @node.xpath("address[@addr][@addrtype='ipv6']").first @ipv6 = addr['addr'] if addr end return @ipv6 end |
#mac ⇒ String
Parses the MAC address of the host.
122 123 124 125 126 127 128 129 130 |
# File 'lib/nmap/host.rb', line 122 def mac unless @mac addr = @node.xpath("address[@addr][@addrtype='mac']").first @mac = addr['addr'] if addr end return @mac end |
#open_ports ⇒ Array<Port>
Parses the open ports of the host.
348 349 350 |
# File 'lib/nmap/host.rb', line 348 def open_ports each_open_port.to_a end |
#os {|os| ... } ⇒ OS
Parses the OS guessing information of the host.
229 230 231 232 233 |
# File 'lib/nmap/host.rb', line 229 def os(&block) if (os = @node.at('os')) @os = OS.new(os,&block) end end |
#ports ⇒ Array<Port>
Parses the scanned ports of the host.
315 316 317 |
# File 'lib/nmap/host.rb', line 315 def ports each_port.to_a end |
#scripts ⇒ Hash{String => String}
The output from the NSE scripts ran against the host.
435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/nmap/host.rb', line 435 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.
43 44 45 |
# File 'lib/nmap/host.rb', line 43 def start_time @start_time ||= Time.at(@node['starttime'].to_i) end |
#status ⇒ Status
Parses the status of the host.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/nmap/host.rb', line 65 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.
381 382 383 |
# File 'lib/nmap/host.rb', line 381 def tcp_ports each_tcp_port.to_a end |
#tcpsequence {|tcpsequence| ... } ⇒ TcpSequence
Parses the Tcp Sequence number analysis of the host.
246 247 248 249 250 |
# File 'lib/nmap/host.rb', line 246 def tcpsequence(&block) if (seq = @node.at('tcpsequence')) @tcpsequence = TcpSequence.new(seq,&block) end end |
#tcptssequence {|tcptssequence| ... } ⇒ TcpTsSequence
Parses the TCP Timestamp sequence number analysis of the host.
280 281 282 283 284 |
# File 'lib/nmap/host.rb', line 280 def tcptssequence(&block) if (seq = @node.at('tcptssequence')) @tcptssequence = TcpTsSequence.new(seq,&block) end end |
#to_s ⇒ String
Converts the host to a String.
455 456 457 |
# File 'lib/nmap/host.rb', line 455 def to_s address.to_s end |
#udp_ports ⇒ Array<Port>
Parses the UDP ports of the host.
414 415 416 |
# File 'lib/nmap/host.rb', line 414 def udp_ports each_udp_port.to_a end |