def main(*args, **kwargs): pp = pprint.PrettyPrinter(width=50, compact=True) # Use your own API key for the Meraki dashboard API api_key = "your_api_key" my_orgs = meraki.myorgaccess(api_key) for org in my_orgs: if 'DevNet Sandbox' in org['name']: my_networks = meraki.getnetworklist(api_key, org['id']) break for network in my_networks: if 'DevNet Always On Read Only' in network['name']: my_net_devices = meraki.getnetworkdevices(api_key, network['id']) networkid = network['id'] break for device in my_net_devices: if 'MV' in device['model']: camera_snapshot = getcamerasnapshot(api_key, networkid, device['serial']) break pp.pprint(camera_snapshot)
def get_org_id(apikey, orgName, suppressprint): #Turns an org name into an org ID result = meraki.myorgaccess(apikey, suppressprint) for row in result: if row['name'] == orgName: return row['id'] raise ValueError('The organization name does not exist')
def get_my_org_id(self) -> int: """ returns our org ID, if we know it, and looks it up if we don't """ if self.org_id == 0: orgs = meraki.myorgaccess(self.apikey, suppressprint=True) for org in orgs: if org["name"] == self.org: self.org_id = org["id"] break return self.org_id
def getOrg(): orglist = [] try: if config.meraki_api != None: logger.info('Get Organization Initiated') org = meraki.myorgaccess(config.meraki_api,suppressprint=True) if org != None: for orgs in org: orglist.append(orgs['id']) logger.info('Organizations Returned') return orglist else: logger.info('Organization List is Empty') return None except Exception as err: logger.error("ERROR in Getting Organization", exc_info=True) return ("ERROR in Getting Organization" + str(err))
def main(*args, **kwargs): pp = pprint.PrettyPrinter(width=41, compact=True) # Use your own API key for the Meraki dashboard API api_key = "your_api_key" my_orgs = meraki.myorgaccess(api_key) for org in my_orgs: if 'DevNet Sandbox' in org['name']: my_networks = meraki.getnetworklist(api_key, org['id']) break for network in my_networks: if 'DevNet Always On Read Only' in network['name']: my_vlans = meraki.getvlans(api_key, network['id']) break pp.pprint(my_vlans)
def merakiclients(): APIKEY = os.getenv("MERAKI_API_KEY") devices = list() clients = list() mOrgs = meraki.myorgaccess(APIKEY) for org in mOrgs: for net in meraki.getnetworklist(APIKEY, org["id"]): devices += meraki.getnetworkdevices(APIKEY, net["id"]) for device in devices: clients += meraki.getclients(APIKEY, device["serial"]) blobclient = BlobServiceClient.from_connection_string(os.getenv("BLOB_CONNECTION_STRING")) container = blobclient.get_container_client(os.getenv("MERAKI_BLOB_CONTAINER")) blobname = "clients-{}.json".format(datetime.date.today().isoformat()) try: container.upload_blob(blobname, data=json.dumps(clients, indent=2)) except Exception as e: print(e) response = "Uploaded {} containing {} clients".format(blobname, len(clients)) return response
"Can't set headers, showing all" print(tabulate(df, headers='keys', tablefmt="fancy_grid")) if not justPrint: user_input = input("Select the row number which contains the " + selector + " you with to explore : ") #print("Org ID = "+ str(df.iloc[1]['id'])) data = str(df.iloc[int(user_input)][column_name]) return data else: return "nada" x = '1' while (x == '1'): apidata = m.myorgaccess(apikey, suppressprint=True) # id|name|samlConsumerUrl|samlConsumerUrls selectedOrg = explore_next(apikey, apidata, ['id', 'name'], "Organization", "id") print( "please select:\n1: Get List of Networks\n2: Get Licenses\n3: Get Inventory\n4: Get Templates\n5: Get SNMP Settings" ) user_input = input("##: ") if user_input == '1': apidata = m.getnetworklist(apikey, selectedOrg, suppressprint=True) #configTemplateId|id|name|organizationId|tags|timeZone|type selectedNetwork = explore_next( apikey, apidata, ['name', 'id', 'tags', 'timeZone', 'type'], "Network", "id")
# API Python module @ https://github.com/meraki/dashboard-api-python/blob/master/meraki.py ##### DO NOT MODIFY ##### from meraki import meraki import random import sys my_key = 'e24759c28edd1d97715a6ba9ea8bc679c5d2706b' orgs = meraki.myorgaccess(my_key) org_names = [org['name'] for org in orgs] index = org_names.index('Public API Lab') my_org = orgs[index]['id'] ##### DO NOT MODIFY ##### # 1. Create a network ######################### ##### START EDITING ##### my_name = 'First Last' my_tags = ['Tag1', 'Tag2', 'Tag3'] my_time = 'US/Pacific' ###### END EDITING ###### ######################### # Get the current list of networks current_networks = meraki.getnetworklist(my_key, my_org) # Get the current networks' names network_names = [network['name'] for network in current_networks] # Was my_name changed from default 'First Last'?
from meraki import meraki import json as pyjson ######################## # Inputs ######################## # Name of the device we want to track client_name = 'Hollyhelen.local' # This is an example ######################## # Get the network ID ######################## apikey = "0d79271f7401f39b20630d7de9ad999c594cb403" myOrgs = meraki.myorgaccess(apikey) print(myOrgs) orgid = myOrgs[0]['id'] print('##### Analizing networks...') myNetworks = meraki.getnetworklist(apikey, orgid) #networkid = myNetworks['id'] # WE DO NOT HAVE PERMISSION TO GET THE INFO FROM NETWORKLIST, BUT WE CAN #USE THE NETWORK ID THEY GAVE US (IN A REAL CASE, THE CODE ABOVE IS CORRECT): networkid = 'N_658651445502946234' ######################## # Get the info from all clients ######################## # Get the serial number of the wifi point (device)
#!/usr/bin/python3.6 from meraki import meraki apikey = "myAPIkey" # get API key from Meraki dashboard orgs = meraki.myorgaccess(apikey, suppressprint=True) company = "myCompany" # insert company name c = list(filter(lambda o: o.get('name') == company, orgs)) if list: c = c[0] orgid = c.get('id') #read all networks networks = meraki.getnetworklist(apikey, orgid, suppressprint=True) for net in networks: netID = net.get('id') netName = net.get('name') print('*' * 80) print('NETWORK NAME {:20} ID {}'.format(netName, netID)) deviceList = meraki.getnetworkdevices(apikey, netID, suppressprint=True) for device in deviceList: if "MX" in device.get('model'): d = 'SECURITY POLICIES FOR DEVICE {} SERIAL {}'.format( device.get('model'), device.get('serial')) print('*' * 80) print(d) print('*' * 80) g = meraki.getmxl3fwrules(apikey, netID, suppressprint=True)
from meraki import meraki import json, os with open(os.path.join(os.pardir,"api/api_credentials.json"), "r") as creds: # Reads the api_credentials.json file for authentication keys = json.load(creds) # Defines the plain text API key generated in the Meraki portal apikey = keys[0]["apikey"] orgids = meraki.myorgaccess(apikey) print(orgids) with open("api_org_ids.json", 'w', ) as f: json.dump(orgids, f, indent=4)
from meraki import meraki from passwords import key myOrgs = meraki.myorgaccess(key) print(myOrgs)
from meraki import meraki import os os.environ['HTTPS_PROXY'] = "http://culproxyvip.safeway.com:8080" print(meraki.myorgaccess('d10aa87866385c57d835bc7e982a022c610c2755'))
net_ids_adm = [] net_ids_captive = [] adm_apnames = [] adm_orgs = [] net_type_adm = [] adm_serial = [] adm_counter = [] cap_apnames = [] cap_orgs = [] net_type_cap = [] cap_serial = [] cap_counter = [] try: logging.info('start time') for org in meraki.myorgaccess(KEY): if org.get('name') == 'CNB - Camera' and org.get('id') == '597852850533433525': continue org_names.append(org.get('name')) org_ids.append(org.get('id')) org_names_ids = sorted(list(zip(org_names, org_ids))) for single in org_names_ids: networks = meraki.getnetworklist(KEY, single[1]) for network in networks: if 'ADMINISTRAÇÃO' in network.get('name'): set_adm = [network.get('organizationId'), network.get('name'), network.get('id')] net_ids_adm.append(set_adm) elif 'CAPTIVE PORTAL WIFI' in network.get('name'): set_captive = [network.get('organizationId'), network.get('name'), network.get('id')]
import logging import requests logging.basicConfig(filename='Devices_Counter.log', level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s') org_ids = [] # all org_ids org_names = [] # all org names online_counter_lst = [] # all orgs online devices offline_counter_lst = [] # all orgs offline devices try: # API Key. KEY = <API KEY> try: # getting all organizations orgs = meraki.myorgaccess(KEY) # creating 2 lists containing the ids and names of all org for org in orgs: org_ids.append(org.get('id')) org_names.append(org.get('name')) except meraki.OrgPermissionError: error_text = 'No permission to access organization.' logging.error('{}'.format(error_text)) print('{}'.format(error_text)) # Creating list of tuples org_names_ids = sorted(list(zip(org_names, org_ids))) # Excluding unnecessary org for this project org_names_ids.__delitem__(4) org_names_sorted = sorted(org_names) org_names_sorted.__delitem__(4)