Class: Nmap::XML::Traceroute

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nmap/xml/traceroute.rb

Overview

Wraps the trace XML element.

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Traceroute

Creates a new traceroute.

Parameters:

  • node (Nokogiri::XML::Element)

    The trace XML element.

Since:

  • 1.0.0



22
23
24
# File 'lib/nmap/xml/traceroute.rb', line 22

def initialize(node)
  @node = node
end

Instance Method Details

#each {|hop| ... } ⇒ Traceroute, Enumerator

Parses the traceroute information for the host.

Yields:

  • (hop)

    Each hop to the host.

Yield Parameters:

  • hop (Hop)

    A hop to the host.

Returns:

  • (Traceroute, Enumerator)

    The traceroute. If no block was given, an enumerator will be returned.

Since:

  • 1.0.0



63
64
65
66
67
68
69
70
71
# File 'lib/nmap/xml/traceroute.rb', line 63

def each
  return enum_for(__method__) unless block_given?

  @node.xpath('hop').each do |hop|
    yield Hop.new(hop['ipaddr'],hop['host'],hop['ttl'],hop['rtt'])
  end

  return self
end

#portInteger?

The port used for the traceroute.

Returns:

  • (Integer, nil)

    The port XML attribute.

Since:

  • 1.0.0



32
33
34
35
36
# File 'lib/nmap/xml/traceroute.rb', line 32

def port
  @port ||= if @node['port']
              @node['port'].to_i
            end
end

#protocolSymbol?

The protocol used for the traceroute.

Returns:

  • (Symbol, nil)

    The proto XML element.

Since:

  • 1.0.0



44
45
46
47
48
# File 'lib/nmap/xml/traceroute.rb', line 44

def protocol
  @protocol ||= if @node['proto']
                  @node['proto'].to_sym
                end
end