Class: Lanet::Traceroute
- Inherits:
-
Object
- Object
- Lanet::Traceroute
- Defined in:
- lib/lanet/traceroute.rb
Constant Summary collapse
- PROTOCOLS =
Supported protocols
i[icmp udp tcp].freeze
- DEFAULT_MAX_HOPS =
Default settings
30- DEFAULT_TIMEOUT =
1- DEFAULT_QUERIES =
3- DEFAULT_PORT =
Starting port for UDP traceroute
33_434
Instance Attribute Summary collapse
-
#max_hops ⇒ Object
readonly
Returns the value of attribute max_hops.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(protocol: :udp, max_hops: DEFAULT_MAX_HOPS, timeout: DEFAULT_TIMEOUT, queries: DEFAULT_QUERIES) ⇒ Traceroute
constructor
A new instance of Traceroute.
- #trace(destination) ⇒ Object
Constructor Details
#initialize(protocol: :udp, max_hops: DEFAULT_MAX_HOPS, timeout: DEFAULT_TIMEOUT, queries: DEFAULT_QUERIES) ⇒ Traceroute
Returns a new instance of Traceroute.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lanet/traceroute.rb', line 20 def initialize(protocol: :udp, max_hops: DEFAULT_MAX_HOPS, timeout: DEFAULT_TIMEOUT, queries: DEFAULT_QUERIES) @protocol = protocol.to_sym @max_hops = max_hops @timeout = timeout @queries = queries @results = [] return if PROTOCOLS.include?(@protocol) raise ArgumentError, "Protocol must be one of #{PROTOCOLS.join(", ")}" end |
Instance Attribute Details
#max_hops ⇒ Object (readonly)
Returns the value of attribute max_hops.
18 19 20 |
# File 'lib/lanet/traceroute.rb', line 18 def max_hops @max_hops end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
18 19 20 |
# File 'lib/lanet/traceroute.rb', line 18 def protocol @protocol end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
18 19 20 |
# File 'lib/lanet/traceroute.rb', line 18 def queries @queries end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
18 19 20 |
# File 'lib/lanet/traceroute.rb', line 18 def results @results end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
18 19 20 |
# File 'lib/lanet/traceroute.rb', line 18 def timeout @timeout end |
Instance Method Details
#trace(destination) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lanet/traceroute.rb', line 32 def trace(destination) @results = [] destination_ip = resolve_destination(destination) begin trace_protocol(destination_ip) rescue StandardError => e raise e unless e..include?("Must run as root/administrator") # Fall back to system traceroute command if we don't have root privileges trace_using_system_command(destination) end @results end |