Class: Nmap::Traceroute

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

Overview

Wraps the trace XML element.

Since:

  • 0.7.0

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Traceroute

Creates a new traceroute.

Parameters:

  • node (Nokogiri::XML::Element)

    The trace XML element.

Since:

  • 0.7.0



19
20
21
# File 'lib/nmap/traceroute.rb', line 19

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:

  • 0.7.0



56
57
58
59
60
61
62
63
64
# File 'lib/nmap/traceroute.rb', line 56

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)

    The port XML attribute.

Since:

  • 0.7.0



29
30
31
# File 'lib/nmap/traceroute.rb', line 29

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

#protocolSymbol

The protocol used for the traceroute.

Returns:

  • (Symbol)

    The proto XML element.

Since:

  • 0.7.0



39
40
41
# File 'lib/nmap/traceroute.rb', line 39

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