Skip to content

Commit 53cc486

Browse files
committed
updated to use the Organization wide BSSID endpoint
1 parent 7f79a94 commit 53cc486

File tree

1 file changed

+43
-53
lines changed

1 file changed

+43
-53
lines changed

bssid.py

+43-53
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
A Python 3 script to pull of the enabled BSSID from an Organization.
99
1010
Required Python modules:
11-
meraki
11+
meraki 1.48.0 or higher
1212
1313
Usage:
1414
bssid.py
1515
16-
If you have only one Organization, it will find all BSSID in each Network
17-
and create a csv for each in Documents/BSSID/Organization
16+
If you have only one Organization, it will find all BSSID
17+
and create a csv for each network in Documents/BSSID/Organization
1818
1919
If you have multiple Organizations, it will ask you which org to run against
2020
@@ -30,11 +30,17 @@
3030

3131

3232
def base_folder():
33+
'''
34+
Check if the root folder exists and create it if not
35+
'''
3336
if not Path.is_dir(loc):
3437
Path.mkdir(loc)
3538

3639

3740
def get_orgs():
41+
'''
42+
get a list of organizations the user has access to and return that dict
43+
'''
3844
orgs = dashboard.organizations.getOrganizations()
3945
org_dict = {}
4046
for i in orgs:
@@ -43,10 +49,17 @@ def get_orgs():
4349

4450

4551
def find_org(org_dict):
52+
'''
53+
If only one organizaiton exists, use that org_id
54+
'''
4655
if len(org_dict) == 1:
4756
org_id = org_dict[0]['id']
4857
org_name = org_dict[0]['name']
4958
else:
59+
'''
60+
If there are multiple organizations, ask the use which one to use
61+
then store that information to be used
62+
'''
5063
org_id = input(
5164
f"Please type the number of the Organization you want to find "
5265
f"the bssid in{json.dumps(org_dict, indent=4)}" "\n")
@@ -55,6 +68,9 @@ def find_org(org_dict):
5568

5669

5770
def org_folder(org_name):
71+
'''
72+
check if the organizaiton folder exists, create if not
73+
'''
5874
loc2 = Path.joinpath(loc, org_name)
5975
if not Path.is_dir(loc2):
6076
Path.mkdir(loc2)
@@ -63,6 +79,7 @@ def org_folder(org_name):
6379
def get_networks(org_id):
6480
net_list = dashboard.organizations.getOrganizationNetworks(
6581
org_id, total_pages='all')
82+
print(net_list)
6683
return net_list
6784

6885

@@ -71,60 +88,35 @@ def find_networks(net_list):
7188
for i in net_list:
7289
if 'wireless' in i['productTypes']:
7390
net_ids[i['id']] = i['name']
74-
net_name = i['name']
75-
return net_ids, net_name
91+
return net_ids
7692

7793

78-
def find_ap(net_ids):
79-
ap_dict = {}
80-
for k, v in net_ids.items():
81-
name = v
82-
lst = []
83-
devices = dashboard.networks.getNetworkDevices(k)
84-
for i in devices:
85-
model = i['model'][:2]
86-
if model == 'MR' or model == 'CW':
87-
dic = {}
88-
if i.get('name') is None:
89-
dic.update(name=i['mac'], serial=i['serial'])
90-
else:
91-
dic.update(name=i['name'], serial=i['serial'])
92-
lst.append(dic)
93-
ap_dict[name] = lst
94-
return ap_dict
95-
96-
97-
def get_bssid(ap_dict, net_ids):
98-
bssid_dict = {}
99-
for k, v in net_ids.items():
100-
name = v
101-
lst = []
102-
for data in ap_dict[name]:
103-
ap = data['serial']
104-
response = dashboard.wireless.getDeviceWirelessStatus(ap)
105-
for value in response['basicServiceSets']:
106-
info_dict = {}
107-
good = value['enabled']
108-
if good is True:
109-
info_dict['name'] = data['name']
110-
info_dict['ssidName'] = value['ssidName']
111-
info_dict['band'] = value['band']
112-
info_dict['bssid'] = value['bssid']
113-
lst.append(info_dict)
114-
bssid_dict[name] = lst
94+
def get_bssid(org_id, net_ids):
95+
'''
96+
dump the BSSID list for the organization
97+
'''
98+
bssid_dict = dashboard.wireless.getOrganizationWirelessSsidsStatusesByDevice\
99+
(org_id, total_pages='all')
115100
return bssid_dict
116101

117102

118103
def file_writer(bssid_dict, net_ids, org_name):
104+
print(f'writing BSSID to file')
119105
for k, v in net_ids.items():
120-
network = v
121-
file = f'{loc}/{org_name}/{network}.csv'
106+
net_name = v
107+
file = f'{loc}/{org_name}/{net_name}.csv'
122108
with open(file, mode='w') as f:
123-
f.write(f"AP Name , SSID Name , Frequency , BSSID" + "\n")
124-
for data in bssid_dict[network]:
125-
f.write(f"{data['name']}, {data['ssidName']}, "
126-
f"{data['band']}, {data['bssid']}" + "\n")
127-
print(f'Your file {network}.csv has been created in {loc} / {org_name}')
109+
f.write(f"AP Name , SSID Name , Frequency , BSSID, AP Serial" + "\n")
110+
for ap in bssid_dict['items']:
111+
network = ap['network']['name']
112+
if net_name == network:
113+
for bss in ap['basicServiceSets']:
114+
f.write(f"{ap['name']}, "
115+
f"{bss['ssid']['name']}, "
116+
f"{bss['radio']['band']} GHz, "
117+
f"{bss['bssid']}, "
118+
f"{ap['serial']}" + "\n")
119+
print(f'Your file {net_name}.csv has been created in {loc}/{org_name}')
128120

129121

130122
def main():
@@ -133,10 +125,8 @@ def main():
133125
org_id, org_name = find_org(org_dict)
134126
org_folder(org_name)
135127
net_list = get_networks(org_id)
136-
net_ids, net_name = find_networks(net_list)
137-
ap_dict = find_ap(net_ids)
138-
bssid_dict = get_bssid(ap_dict, net_ids)
139-
print(f'writing BSSID to file')
128+
net_ids = find_networks(net_list)
129+
bssid_dict = get_bssid(org_id, net_ids)
140130
file_writer(bssid_dict, net_ids, org_name)
141131

142132

0 commit comments

Comments
 (0)