Class: TraceRouterRecord
- Inherits:
-
Object
- Object
- TraceRouterRecord
- Defined in:
- lib/TraceRouter.rb
Instance Attribute Summary collapse
-
#routers ⇒ Object
readonly
Returns the value of attribute routers.
-
#timeStamp ⇒ Object
Returns the value of attribute timeStamp.
Instance Method Summary collapse
-
#initialize ⇒ TraceRouterRecord
constructor
A new instance of TraceRouterRecord.
- #resolve(ip) ⇒ Object
Constructor Details
#initialize ⇒ TraceRouterRecord
Returns a new instance of TraceRouterRecord.
19 20 21 |
# File 'lib/TraceRouter.rb', line 19 def initialize @routers = [] end |
Instance Attribute Details
#routers ⇒ Object (readonly)
Returns the value of attribute routers.
16 17 18 |
# File 'lib/TraceRouter.rb', line 16 def routers @routers end |
#timeStamp ⇒ Object
Returns the value of attribute timeStamp.
17 18 19 |
# File 'lib/TraceRouter.rb', line 17 def timeStamp @timeStamp end |
Instance Method Details
#resolve(ip) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/TraceRouter.rb', line 23 def resolve(ip) begin `traceroute -n #{ip}`.each_line do |line| router = line.scan(/^\s*\d+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+.*$/) @routers << router[0][0] unless router.empty? end rescue return false end # Don't include the IP of the destination host @routers.pop if @routers.size > 0 && @routers[-1] == ip @timeStamp = Time.now() return true end |