forked from meraki/automation-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbssid.py
executable file
·88 lines (71 loc) · 2.44 KB
/
bssid.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
read_me = '''
A Python 3 script to pull of the enabled BSSID from a specified network.
Required Python modules:
meraki
Usage:
bssid.py Network Name
If you have only one Organization, it will search for the Network name.
If you have multiple Organizations, it will ask you which org to run against
API Key
requires you to have your API key in env vars as 'MERAKI_DASHBOARD_API_KEY'
'''
import meraki
import sys
import os
from os.path import expanduser
import json
ap_list = {}
bssid_list = []
loc = expanduser('~/Documents/BSSID/')
dashboard = meraki.DashboardAPI(suppress_logging=True)
def getLocation():
if not os.path.isdir(loc):
os.makedirs(loc)
def getOrgs(net_name):
orgs = dashboard.organizations.getOrganizations()
if len(orgs) == 1:
for dic in orgs:
orgID = dic['id']
getNetworks(orgID,net_name)
else:
org_list = {}
for dic in orgs:
org_list[dic['name']] = dic['id']
orgID = input(f'Please type in the number of the Organization name that you would like to query{json.dumps(org_list, indent = 4)}' "\n")
getNetworks(orgID,net_name)
def getNetworks(orgID, net_name):
networks = dashboard.organizations.getOrganizationNetworks(orgID, total_pages='all')
for dic in networks:
if dic['name'] == net_name:
network_id = dic['id']
getAP(network_id)
else:
print(f'We did not find {net_name} in your organization(s)')
sys.exit()
def getAP(network_id):
devices = dashboard.networks.getNetworkDevices(network_id)
for dic in devices:
model = dic['model'][:-2]
if model == 'MR':
ap_list[dic['name']] = dic['serial']
def getBss(net_name):
with open(loc + net_name + '.csv', 'w') as f:
f.write(f"AP Name , SSID Name , Frequency , BSSID" + "\n")
for k ,v in ap_list.items():
response = dashboard.wireless.getDeviceWirelessStatus(v)
for data in response['basicServiceSets']:
good = data['enabled']
if good == True:
f.write(f"{k} , {data['ssidName']} , {data['band']} , {data['bssid']}" + "\n")
if __name__ == '__main__':
try:
sys.argv[1]
except IndexError:
print("Please provide a Network Name")
sys.exit()
else:
net_name= ' '.join(sys.argv[1:])
getLocation()
getOrgs(net_name)
getBss(net_name)