Skip to content

Instantly share code, notes, and snippets.

@skgsergio
Last active July 20, 2022 07:53
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 skgsergio/93cab6154f6d00bc8a4bab4b70ea41df to your computer and use it in GitHub Desktop.
Save skgsergio/93cab6154f6d00bc8a4bab4b70ea41df to your computer and use it in GitHub Desktop.
import sys
import json
import urllib.request
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} TRACEROUTE_ICMP_MEASUREMENT_ID")
sys.exit(1)
with urllib.request.urlopen(f"https://atlas.ripe.net/api/v2/measurements/{sys.argv[1]}/results/?format=json") as url:
resultset = json.load(url)
suspected_bogus = set()
# Detect probes with broken connectivity by checking if last hop didn't reply
# then record the previous hop as suspected bogus node.
for result in sorted(resultset, key=lambda x: x["prb_id"]):
hops = sorted(result["result"], key=lambda x: -x["hop"])
if all("x" in r for r in hops[0]["result"]): # and hops[0]["hop"] == 255?
print(f"Probe {result['prb_id']}... failed!")
# Search last
last_good = None
for hop in hops:
broken = ["x" in r for r in hop["result"]]
if not all(broken):
last_good = hop
break
if last_good:
last_hop = {r['from'] for r in last_good['result'] if 'from' in r}
suspected_bogus |= last_hop
print(f"\tLast hop: {last_hop}")
else:
print("\tNo last hop found. Traceroute blocked?")
print(f"\nSuspected bogus nodes: {suspected_bogus}\n")
# Check if probes with working connectivity contain the suspected bogus nodes
# anywhere in the trace.
for result in sorted(resultset, key=lambda x: x["prb_id"]):
hops = sorted(result["result"], key=lambda x: -x["hop"])
if not all("x" in r for r in hops[0]["result"]):
print(f"Probe {result['prb_id']}... ok!")
for hop in hops:
hop_ips = {r["from"] for r in hop["result"] if "from" in r}
if any(ip in suspected_bogus for ip in hop_ips):
print(f"\tHop {hop['hop']} has suspected bogus node but has connectivity: {hop_ips}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment