-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiremaps.py
33 lines (25 loc) · 1.27 KB
/
wiremaps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import requests, json, re
# script that shows how to use the wiremaps API, generates a dotfile to generate a network map of the information in wiremaps by vincent bernat (https://github.com/vincentbernat/wiremaps)
# the api base url should go here (replace WIREMAPSHOST with the IP/Hostname of the wiremaps box and PORT with the port twistd is running at
api_url = """http://WIREMAPSHOST:PORT/api/1.1/"""
all_equipment = json.loads(requests.get(api_url + "equipment/").text)
connections = {}
print """digraph network {"""
for (node, ip) in all_equipment:
ports = json.loads(requests.get(api_url + "equipment/" + ip).text)
for (ifindex, ifname, ifdescr, ifstatus, ifspeed, unk1, unk2) in ports:
portinfo = json.loads(requests.get(api_url + "equipment/" + ip + "/" + str(ifindex)).text)
if (len(portinfo) > 2):
for pstuff in portinfo:
if pstuff[0].find('Host') != -1:
node = re.sub(r'\([^)]*\)', '', node)
node = re.sub(r' ', '_', node)
node = re.sub(r'\.', '-', node)
connected = re.sub(r'\([^)]*\)', '', pstuff[2])
connected = re.sub(r' ', '_', connected)
connected = re.sub(r'\.', '-', connected)
connections[node + " -> " + connected] = 1
for connection in connections.keys():
print connection + """;"""
print """}"""