Search for a device through the REST API
You can search through all discovered devices on your ExtraHop system by specifying your criteria (such as IP address or discovery ID) and then export the list of devices and their associated metadata to a file format that is readable through a third-party application like Microsoft Excel or any CSV reader. For example, you might want to view and export the IP addresses of each VMware device on your network.
You can test device search queries before incorporating them into a script by running the queries in the ExtraHop REST API Explorer. This guide includes methods for both the REST API Explorer and a sample Python script.
Search for a device through the REST API Explorer
Python script example
The following example Python script searches for a list of devices by IP address. The script then outputs the ExtraHop discovery ID for each IP address.
- HOST
- The IP address or hostname of the Discover or Command appliance.
- APIKEY
- The API key generated from the Discover or Command appliance.
- IP_ADDR_LIST
- An array of IP addresses.
#!/usr/bin/python3 import json import requests HOST = 'https://extrahop.example.com' APIKEY = '123456789abcdefghijklmnop' IP_ADDR_LIST = [ '10.10.10.200', '10.10.10.201', '10.10.10.202', '10.10.10.203' ] def searchDevice(search): url = HOST + '/api/v1/devices/search' headers = {'Authorization': 'ExtraHop apikey=%s' % APIKEY} r = requests.post(url, headers=headers, verify=False, data=json.dumps(search)) return r.json()[0] for ip in IP_ADDR_LIST: search_filter = { "filter": { "field": "ipaddr", "operand": ip, "operator": "=" } } device = searchDevice(search_filter) print(ip) print(' ' + device['discovery_id'])
Thank you for your feedback. Can we contact you to ask follow up questions?