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.
-
#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.
-
#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.
27 28 29 30 31 |
# File 'lib/nmap/host.rb', line 27 def initialize(node,&block) @node = node block.call(self) if block end |
Instance Method Details
#address ⇒ String
The address of the host.
174 175 176 |
# File 'lib/nmap/host.rb', line 174 def address ip || mac end |
#addresses ⇒ Array<Host>
Parses the addresses of the host.
106 107 108 |
# File 'lib/nmap/host.rb', line 106 def addresses each_address.to_a end |
#each(&block) ⇒ Object
Parses the open ports of the host.
366 367 368 |
# File 'lib/nmap/host.rb', line 366 def each(&block) each_open_port(&block) end |
#each_address {|addr| ... } ⇒ Host, Enumerator
Parses each address of the host.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/nmap/host.rb', line 85 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.
191 192 193 194 195 196 197 198 199 |
# File 'lib/nmap/host.rb', line 191 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.
275 276 277 278 279 280 281 282 283 |
# File 'lib/nmap/host.rb', line 275 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.
242 243 244 245 246 247 248 249 250 |
# File 'lib/nmap/host.rb', line 242 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.
308 309 310 311 312 313 314 315 316 |
# File 'lib/nmap/host.rb', line 308 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.
341 342 343 344 345 346 347 348 349 |
# File 'lib/nmap/host.rb', line 341 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.
53 54 55 |
# File 'lib/nmap/host.rb', line 53 def end_time Time.at(@node['endtime'].to_i) end |
#hostnames ⇒ Array<String>
Parses the hostnames of the host.
207 208 209 |
# File 'lib/nmap/host.rb', line 207 def hostnames each_hostname.to_a end |
#ip ⇒ String
The IP address of the host.
164 165 166 |
# File 'lib/nmap/host.rb', line 164 def ip ipv6 || ipv4 end |
#ipv4 ⇒ String
Parses the IPv4 address of the host.
132 133 134 135 136 137 138 139 140 |
# File 'lib/nmap/host.rb', line 132 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.
148 149 150 151 152 153 154 155 156 |
# File 'lib/nmap/host.rb', line 148 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.
116 117 118 119 120 121 122 123 124 |
# File 'lib/nmap/host.rb', line 116 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.
291 292 293 |
# File 'lib/nmap/host.rb', line 291 def open_ports each_open_port.to_a end |
#os {|os| ... } ⇒ OS
Parses the OS guessing information of the host.
223 224 225 226 227 |
# File 'lib/nmap/host.rb', line 223 def os(&block) os = @node.at('os') return OS.new(os,&block) if os end |
#ports ⇒ Array<Port>
Parses the scanned ports of the host.
258 259 260 |
# File 'lib/nmap/host.rb', line 258 def ports each_port.to_a end |
#scripts ⇒ Hash{String => String}
The output from the NSE scripts ran against the host.
378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/nmap/host.rb', line 378 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.
41 42 43 |
# File 'lib/nmap/host.rb', line 41 def start_time Time.at(@node['starttime'].to_i) end |
#status ⇒ Status
Parses the status of the host.
63 64 65 66 67 68 69 70 |
# File 'lib/nmap/host.rb', line 63 def status status = @node.at('status') return Status.new( status['state'].to_sym, status['reason'] ) end |
#tcp_ports ⇒ Array<Port>
Parses the TCP ports of the host.
324 325 326 |
# File 'lib/nmap/host.rb', line 324 def tcp_ports each_tcp_port.to_a end |
#to_s ⇒ String
Converts the host to a String.
398 399 400 |
# File 'lib/nmap/host.rb', line 398 def to_s address.to_s end |
#udp_ports ⇒ Array<Port>
Parses the UDP ports of the host.
357 358 359 |
# File 'lib/nmap/host.rb', line 357 def udp_ports each_udp_port.to_a end |