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()