Home

Awesome

trparse

Parses the output of a traceroute or traceroute6 execution into an AST (Abstract Syntax Tree) built up from:

Every node is printable and the entire tree is printable from the root.

Supports the following info. Parsed info in bold:

Usage

import trparse
s = <some_output_from_traceroute> 
# Parse the traceroute output
traceroute = trparse.loads(s)
# You can print the result
print traceroute
# Save it as string
tr_str = str(traceroute) 
# Or travel the tree
hop = traceroute.hops[0]
probe = hop.probes[0]
# And print the IP address
print probe.ip

Data structures

Considerations

trparse is based on the output of the traceroute command in OSX and Linux. It parses the text based on regular expressions, so there are some tokens it expects to find in a specific format. For example:

Windows's tracert output does not meet these conditions so it won't work in a Widows system. Maybe in a future release.

Changelog

v0.3.0

  1. Rebuilt the parsing function to support RTT, IP, Name and ASN in any order inside the hop/probe.
  2. RTT values are now Decimal.
  3. Improved __str__ output.
  4. Moved ASN from Hop to Probe