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:
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 probe = hop.probes # And print the IP address print probe.ip
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.