Class: EM::Traceroute::Hop
- Inherits:
-
Object
- Object
- EM::Traceroute::Hop
- Defined in:
- lib/emtraceroute/hop.rb
Instance Attribute Summary collapse
-
#found ⇒ Object
Returns the value of attribute found.
-
#icmp ⇒ Object
Returns the value of attribute icmp.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#location ⇒ Object
Returns the value of attribute location.
-
#pkt ⇒ Object
Returns the value of attribute pkt.
-
#remote_icmp ⇒ Object
Returns the value of attribute remote_icmp.
-
#remote_ip ⇒ Object
Returns the value of attribute remote_ip.
-
#tries ⇒ Object
Returns the value of attribute tries.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#initialize(target, ttl) ⇒ Hop
constructor
A new instance of Hop.
- #to_s ⇒ Object
Constructor Details
#initialize(target, ttl) ⇒ Hop
Returns a new instance of Hop.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/emtraceroute/hop.rb', line 4 def initialize target, ttl @found = false @tries = 0 @last_try = 0 @remote_ip = nil @remote_icmp = nil @location = "" @ttl = ttl @ip = Iphdr.new(Socket::IPPROTO_ICMP, '0.0.0.0', target) # IP header @ip.ttl = ttl @ip.id += ttl @icmp = Icmphdr.new("traceroute") # ICMP header @icmp.id = @ip.id @ip.data = @icmp.assemble @pkt = @ip.assemble end |
Instance Attribute Details
#found ⇒ Object
Returns the value of attribute found.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def found @found end |
#icmp ⇒ Object
Returns the value of attribute icmp.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def icmp @icmp end |
#ip ⇒ Object
Returns the value of attribute ip.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def ip @ip end |
#location ⇒ Object
Returns the value of attribute location.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def location @location end |
#pkt ⇒ Object
Returns the value of attribute pkt.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def pkt @pkt end |
#remote_icmp ⇒ Object
Returns the value of attribute remote_icmp.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def remote_icmp @remote_icmp end |
#remote_ip ⇒ Object
Returns the value of attribute remote_ip.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def remote_ip @remote_ip end |
#tries ⇒ Object
Returns the value of attribute tries.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def tries @tries end |
#ttl ⇒ Object
Returns the value of attribute ttl.
3 4 5 |
# File 'lib/emtraceroute/hop.rb', line 3 def ttl @ttl end |
Instance Method Details
#to_s ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/emtraceroute/hop.rb', line 29 def to_s if @found ip = ":: #{remote_ip.src}" ping = "#{(@found - @last_try).round(3)}s" else ip = "??" ping = "-" end location = ":: #{@location}" "#{@ttl}. #{ping} #{ip} #{location}" end |