forked from MrKalzu/traceroute_map
TEMP
This commit is contained in:
@ -8,6 +8,8 @@ from .db import Database
|
||||
|
||||
|
||||
def parse_traceroute_output(data: str, origin: str):
|
||||
# TODO: data validation
|
||||
|
||||
lines = data.strip().split("\n")
|
||||
target = lines[0].split()[2]
|
||||
|
||||
@ -15,21 +17,26 @@ def parse_traceroute_output(data: str, origin: str):
|
||||
|
||||
trace = {"target": target, "created": created, "origin": origin, "hops": []}
|
||||
|
||||
prev_latency = 0
|
||||
prev_latency = None
|
||||
|
||||
for line in lines[1:]:
|
||||
hop_info = line.split()
|
||||
print("LINE:", hop_info)
|
||||
try:
|
||||
# Regular lines.
|
||||
number, name, ip, latency, _ = hop_info
|
||||
latency = float(latency)
|
||||
hop = {
|
||||
"created": created,
|
||||
"number": number,
|
||||
"name": name,
|
||||
"ip": ip.strip("()"),
|
||||
"latency": float(latency),
|
||||
"latency": latency,
|
||||
"link_latency": round(latency if prev_latency else latency, 3),
|
||||
}
|
||||
prev_latency = latency
|
||||
except ValueError:
|
||||
# Asterisks, no data found for hop.
|
||||
number, name = hop_info
|
||||
hop = {
|
||||
"created": created,
|
||||
@ -37,6 +44,7 @@ def parse_traceroute_output(data: str, origin: str):
|
||||
"name": name,
|
||||
"ip": None,
|
||||
"latency": None,
|
||||
"link_latency": "?",
|
||||
}
|
||||
|
||||
trace["hops"].append(hop)
|
||||
|
Reference in New Issue
Block a user