Fetching client Names correspond to IPS

Sal915
Conversationalist

Fetching client Names correspond to IPS

Hello Folks,

I just want to confirm if it is possible to fetch the client name (laptop name) if I have a list of IP addresses in hand.

If yes,

I am trying to retrieve the device names corresponding to the IPs that I have, in order to create a list of IPs to use for different projects. Otherwise, I would need to check each device name one by one corresponding to the IP.

I am running Python code. It was executed with no errors, but it is not giving me the name of the device. However, when I manually check in the client section of the Cisco Meraki dashboard, and search the IP in the clients section, it gives me the device name (Client).



code:

import requests

# Your API key, organization ID, and network ID
API_KEY = 'abcd'
ORG_ID =  'abcd'
NETWORK_ID =  'abcd'
IP_ADDRESS = '0.0.0.0' # Single IP address

# Meraki API endpoint URL for clients
clients_url = f"https://api.meraki.com/api/v1/networks/{NETWORK_ID}/clients"

# Set request headers
headers = {
"X-Cisco-Meraki-API-Key": API_KEY,
"Content-Type": "application/json"
}

# Make GET request to retrieve clients
response = requests.get(clients_url, headers=headers)

# Check rate limit headers
print("Rate Limit Headers:")
for header, value in response.headers.items():
if header.startswith('X-RateLimit'):
print(f"{header}: {value}")

# Check if request was successful
if response.status_code == 200:
clients = response.json()

# Find client with specified IP address
client_info = None
for client in clients:
if client['ip'] == IP_ADDRESS:
client_info = client
break

# Print client information
if client_info:
print("Client Information:")
print(client_info)
else:
print(f"No client found for the specified IP address {IP_ADDRESS}.")
else:
print("Error:", response.status_code, ",", response.text)

Any help will be greatly appreciated.

regards,
Sal

2 Replies 2
PhilipDAth
Kind of a big deal
Kind of a big deal

This is a snippet of a script I used for finding Raspberry Pi's in a network using the Meraki Pyhton SDK.

 

		try:
			for client in dashboard.networks.getNetworkClients(net['id'],total_pages='all',timespan=7*86400,mac="b8:27:eb"):
				if(client['mac'].startswith("b8:27:eb:")):
					print(f"\"{net['name']}\",{client['mac']},{client['ip']},\"{client['description']}\"")
		except meraki.exceptions.APIError as e:
			print(f"Skipping {net['name']}: {e.reason}",file=sys.stderr)

 

The field you are wanting is client['description']. 

Sal915
Conversationalist

Thank you Sir,  I made some changes in it and also import ips via Excel file and now I have client [description].

Kudos.

regards,
Sal

Get notified when there are additional replies to this discussion.