Created
March 16, 2014 23:59
-
-
Save drldcsta/9591670 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/awk | |
| #before processing lines, check if "src" variable has been passed | |
| #If so, print it out, if not just print "origin" | |
| #Set the field separator to be '(' or ')' | |
| BEGIN { | |
| if (src) { | |
| printf "%s -> ", src | |
| } else { | |
| printf "%s -> ", "origin" | |
| } | |
| FS = "[()]" | |
| } | |
| #Now for line by line processing | |
| #If line contains "(", pull out the IP from the line and print it | |
| #for every line with a hop processed, we'll keep track of the hop IP | |
| #If this is the first line, then the IP is the destination, so set | |
| #dest variable to that IP. but don't increment hop count If it's not the first line, | |
| #then increment the hop count up. | |
| { | |
| if ($0 ~ /\(/) { | |
| printf "%s -> ", $2 | |
| lasthop = $2 | |
| if (! dest) { | |
| dest = lasthop | |
| } else { | |
| hops++ | |
| } | |
| } | |
| } | |
| #Once all lines have been processed and traceroute is done | |
| #if the last hop hit doesn't match the dest, the trace failed | |
| # | |
| END { | |
| if (lasthop != dest) { | |
| print "DEATH, ", hops , " hops" | |
| } else { | |
| if (hops < 2) { | |
| print "No Route, ", hops , " hops" | |
| } else { | |
| print "SUCCESS, ", hops , " hops" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment