Skip to content

Instantly share code, notes, and snippets.

@emilgaripov
Last active September 10, 2020 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilgaripov/816ecef9bda3d32ee73315173f33e763 to your computer and use it in GitHub Desktop.
Save emilgaripov/816ecef9bda3d32ee73315173f33e763 to your computer and use it in GitHub Desktop.
traceroute.textfsm
traceroute = """
r2#traceroute 90.0.0.9 source 33.0.0.2
traceroute 90.0.0.9 source 33.0.0.2
Type escape sequence to abort.
Tracing the route to 90.0.0.9
VRF info: (vrf in name/id, vrf out name/id)
1 10.0.12.1 1 msec 0 msec 0 msec
2 15.0.0.5 0 msec 5 msec 4 msec
3 57.0.0.7 4 msec 1 msec 4 msec
4 79.0.0.9 4 msec * 1 msec
"""
with open("traceroute.template") as template:
fsm = textfsm.TextFSM(template)
result = fsm.ParseText(traceroute)
print(fsm.header)
print(result)
"""
Example:
['ID', 'Hop']
[['1', '10.0.12.1'], ['2', '15.0.0.5'], ['3', '57.0.0.7'], ['4', '79.0.0.9']]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment