03-25-2025 09:42 AM
Hi All
I have a need to add what switch an endpoint o physically connected to. Currently, I am have the port information but since we have 8 switch stacks there is a need to which switch as well. I am currently using getOrganizationClientsSearch and this everything except the switch name. Is there an option to get the switch name based on the client connection? If so, whats the best way to add that in to my current code? Thanks in advance!
Below is my code snippet:
def find_device():
clearconsole()
API_KEY = get_meraki_api_key()
dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)
organization_id = '412637'
mac = input (Fore.WHITE + Style.BRIGHT + '\nWhich device are you trying to find (xx:xx:xx:xx:xx:xx): ')
response = dashboard.organizations.getOrganizationClientsSearch(
organization_id, mac, total_pages='all'
)
mac = response['mac']
record = response['records']
#print (response)
print (Fore.GREEN,Style.BRIGHT + '\n' + 'Here is what I found: ' + '\n')
print (Fore.WHITE,Style.BRIGHT + 'MAC Address: ' + Fore.YELLOW,Style.BRIGHT,response['mac'])
print (Fore.WHITE,Style.BRIGHT + 'IP Address: ' + Fore.YELLOW,Style.BRIGHT,record[0]['ip'])
if record[0]['description'] is not None:
print (Fore.WHITE,Style.BRIGHT + 'Description: ' + Fore.YELLOW,Style.BRIGHT,record[0]['description'])
if response['manufacturer'] is not None:
print (Fore.WHITE,Style.BRIGHT + 'Manufacture: ' + Fore.YELLOW,Style.BRIGHT,response['manufacturer'])
if record[0]['os'] is not None:
print (Fore.WHITE,Style.BRIGHT + 'OS: ' + Fore.YELLOW,Style.BRIGHT,record[0]['os'])
if record[0]['vlan'] > "0":
print (Fore.WHITE,Style.BRIGHT + "VLAN: " + Fore.YELLOW,Style.BRIGHT,record[0]['vlan'])
print (Fore.WHITE,Style.BRIGHT +"Network: "+ Fore.YELLOW,Style.BRIGHT,record[0]['network']['name'])
print (Fore.WHITE,Style.BRIGHT +"Device Type: "+ Fore.YELLOW + Style.BRIGHT,record[0]['network']['productTypes'])
if "wireless" in record[0]['network']['productTypes']:
print (Fore.WHITE,Style.BRIGHT +"SSID: "+ Fore.YELLOW + Style.BRIGHT,record[0]['ssid'])
if (("switch" in record[0]['network']['productTypes']) and (record[0]['switchport'] is not None)):
#if record[0]['network']['productType'] is not None:
print (Fore.WHITE,Style.BRIGHT +"Switchport: "+ Fore.YELLOW + Style.BRIGHT,record[0]['switchport'])
if "None" == record[0]['user']:
print (Fore.WHITE,Style.BRIGHT +"User: "+ Fore.YELLOW + Style.BRIGHT,record[0]['user'])
print (Fore.WHITE,Style.BRIGHT +"Current Status: "+ Fore.YELLOW + Style.BRIGHT,record[0]['status'] + Style.RESET_ALL)
print ("\n")
whats_next = input ("\nWhat's Next: (M)ain Menu, (S)earch for another, or (Q)uit? ")
if whats_next == "M" or "m":
clearconsole()
main_menu()
if whats_next == "S" or "s":
clearconsole()
find_device()
if whats_next == "Q" or "q":
clearconsole()
exit()
03-25-2025 09:47 AM
You need to use the getDeviceLldpCdp Endpoint to get LLDP/CDP information, including the switch name and port details and modify your code adding a function to retrieve LLDP/CDP.
Get Device Lldp Cdp - Meraki Dashboard API v1 - Cisco Meraki Developer Hub
03-25-2025 09:51 AM
The recent device mac field in that call you are using would get you what you need to then use this call: https://developer.cisco.com/meraki/api-v1/get-organization-inventory-devices/ to get the device names for each device and then you can tie them together in your code.
I don't do much in python so I can't help with the code you'd need to add but hopefully the above will steer you.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide