forked from meraki/automation-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbssid.py
executable file
·105 lines (81 loc) · 2.84 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/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
from pathlib import Path
import json
net_list = {}
p = Path.home()
loc = p / 'Documents' / 'BSSID'
dashboard = meraki.DashboardAPI(suppress_logging=True)
def getLocation1():
if not Path.is_dir(loc):
Path.mkdir(loc)
def getlocation2(loc2):
if not Path.is_dir(loc2):
Path.mkdir(loc2)
def getOrgs():
orgs = dashboard.organizations.getOrganizations()
if len(orgs) == 1:
for dic in orgs:
orgID = dic['id']
orgName = dic['name']
loc2 = loc / orgName
getlocation2(loc2)
getNetworks(orgID, orgName)
else:
org_list = {}
for dic in orgs:
org_list[dic['id']] = dic['name']
orgID = input(f'Please type in the number of the Organization name '
f'that you would like to query {json.dumps(org_list, indent=4)}' "\n")
orgName = org_list.get(orgID)
loc2 = loc / orgName
getlocation2(loc2)
getNetworks(orgID, orgName)
def getNetworks(orgID, orgName):
networks = dashboard.organizations.getOrganizationNetworks(
orgID, total_pages='all')
for dic in networks:
if 'wireless' in dic['productTypes']:
net_list[dic['id']] = dic['name']
for k, v in net_list.items():
net_id = k
net_name = v
getAP(net_id, net_name, orgName)
def getAP(net_id, net_name, orgName):
devices = dashboard.networks.getNetworkDevices(net_id)
ap_list = {}
for dic in devices:
model = dic['model'][:2]
if model == 'MR' or model == 'CW':
if dic.get('name') is None:
ap_list[dic['mac']] = dic['serial']
else:
ap_list[dic['name']] = dic['serial']
getBss(net_name, orgName, ap_list)
def getBss(net_name, orgName, ap_list):
bss = f'{loc}/{orgName}/{net_name}.csv'
with open(bss, mode='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 is True:
f.write(f"{k} , {data['ssidName']} , {data['band']}\
, {data['bssid']}" + "\n")
print(f'Your file {net_name}.csv has been creeated in {loc} / {orgName}')
if __name__ == '__main__':
getLocation1()
getOrgs()