Initial code commit
This commit is contained in:
parent
3549ef5d29
commit
61469a675e
|
@ -0,0 +1,85 @@
|
|||
class Route:
|
||||
def __init__(self, network, via, moi):
|
||||
self.network = network
|
||||
self.via = via
|
||||
self.moi = moi
|
||||
|
||||
def getRoute(self):
|
||||
return self.network
|
||||
|
||||
def getVia(self):
|
||||
return self.via
|
||||
|
||||
def getMoi(self):
|
||||
return self.moi
|
||||
|
||||
def __str__(self):
|
||||
return "route: [Network: "+self.network+", Via: " + self.via+"]"
|
||||
|
||||
def getRoutes(babelArray, myID):
|
||||
routes = []
|
||||
|
||||
for line in babelArray:
|
||||
elements = line.split(" ")
|
||||
|
||||
if elements[0] == "add" and elements[1] == "route":
|
||||
routes.append(Route(elements[4], elements[10], myID))
|
||||
|
||||
return routes
|
||||
|
||||
|
||||
def babelCollect(ip, port):
|
||||
import subprocess
|
||||
babelData = subprocess.getoutput("bash -c \"echo dump | ncat "+ip+" "+port+" --no-shutdown -i 1\"")
|
||||
|
||||
"Only valid ncat one would have this (as the connection succeeded and we got a babel daemon response)"
|
||||
if "my-id" in babelData:
|
||||
babelArray = babelData.split("\n")
|
||||
babelID = babelArray[3].split(" ")[1]
|
||||
print("My ID: "+babelID)
|
||||
|
||||
routes = getRoutes(babelArray, babelID)
|
||||
return routes
|
||||
|
||||
return None
|
||||
|
||||
def collectAllRoutes(peersFile):
|
||||
file = open(peersFile, "r")
|
||||
data = file.read()
|
||||
|
||||
allRoutes = []
|
||||
|
||||
for peer in data.split("\n"):
|
||||
nodeIP = peer.split(" ")[0]
|
||||
nodePort = peer.split(" ")[1]
|
||||
|
||||
routes = babelCollect(nodeIP, nodePort)
|
||||
if routes != None:
|
||||
for route in routes:
|
||||
allRoutes.append(route)
|
||||
|
||||
return allRoutes
|
||||
|
||||
def makeGraph(peersFile):
|
||||
routes = collectAllRoutes(peersFile)
|
||||
print("Collected "+str(len(routes))+" routes")
|
||||
|
||||
graph="graph networkMap {"
|
||||
|
||||
"Yeeet"
|
||||
#graph+="graph [pad=\"5\", nodesep=\"0.1\", ranksep=\"10\"]"
|
||||
|
||||
for route in routes:
|
||||
graph += "\""+route.getMoi()+"\" -- \""+route.getVia() +"\" [label=\""+route.getRoute()+"\"]"
|
||||
|
||||
graph+="}"
|
||||
|
||||
"Write out graph to disk"
|
||||
file = open("thing.dot","w")
|
||||
file.write(graph)
|
||||
file.close()
|
||||
|
||||
import os
|
||||
os.system("cat thing.dot | dot -Tsvg -o graph.svg")
|
||||
|
||||
makeGraph("peers.list")
|
|
@ -0,0 +1,8 @@
|
|||
202:cf0e:46da:edac:470b:d9f0:966a:7ee9 2222
|
||||
200:5667:c358:20c7:2f0c:7e01:4ee8:38fe 2222
|
||||
201:cb93:9864:4f8c:d2d7:264b:6fe:ba73 2222
|
||||
200:74e1:ddb:836b:8d46:6478:be06:8ff7 2222
|
||||
200:f8fd:8493:cf13:618b:6684:6964:f00b 2222
|
||||
200:a4df:d66c:3f3a:b551:5224:c32f:cf8d 2222
|
||||
220:bfe2:bf50:3c25:7597:795b:4323:6771 2222
|
||||
201:5618:2fc6:5e92:23a5:bdcc:4300:3966 2222
|
Loading…
Reference in New Issue