Skip to content
View in the app

A better way to browse. Learn more.

Gear Crushers

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Use API to get DHCP info

Featured Replies

Here are three steps to generate a list of ranges with a given DHCP option set.

First you use a WAPI GET operation on the "range" object to ask for a list of all known DHCP ranges. An example Curl command is as follows:

curl --tlsv1 --insecure --user 'admin:infoblox' --header 'Content-Type:application/json' \
    'https://gm.example.com/wapi/v1.0/range'

Then you have to do a GET for each range (using the returned '_ref' value for the range) to get a list of the DHCP options for that range.

curl --tlsv1 --insecure --user 'admin:infoblox' --header 'Content-Type:application/json' \
    'https://gm.example.com/wapi/v1.0/range/ZG5zLmRoY3BfcmFuZ2UkMTkyLjE2OC4yMDEuMTAwLzE5Mi4xNjguMjAxLjE0O...

Then you have to loop through the returned options for that range and look for the particular option of interest.

Below is a complete working program in Python (with error-checking code removed in the interests of space). You can adapt it by changing the section with the grid master URL, local userid and password, whether your GM uses a self-signed certificate or not, and the DHCP option number you're interested in. The program uses WAPI version 1.0 and so should work on any NIOS version supporting the RESTful API.

# Import the required Python modules.
import requests
import json
import csv

# Set parameters to access the Infoblox API for your own grid master.
url = 'https://gm.example.com/wapi/v1.0/'
id = 'admin'
pw = 'infoblox'
valid_cert = True  # False if self-signed certificate
desired_option = 7  # DHCP option to look for

# Retrieve DHCP ranges (up to first 2000, increase this if needed).
r = requests.get(url + 'range',
                 params={'_max_results': str(2000)},
                 auth=(id, pw),
                 verify=valid_cert)
ranges = r.json()

# Retrieve the options for each range, look for the option we're
# interested in.
discovered_options = []
for range in ranges:
    r = requests.get(url + range['_ref'],
                     params={'_return_fields': 'options'},
                     auth=(id, pw),
                     verify=valid_cert)
    options = r.json()['options']
    for option in options:
        if (option['vendor_class'] == 'DHCP' and
            option['num'] == desired_option):
            option_info = [range['network'],
                           range['start_addr'],
                           range['end_addr'],
                           option['num'],
                           option['value']]
            discovered_options.append(option_info)

# Print information about the ranges containing the option and the
# option's value in each range.
with open('ranges-with-option.csv', 'wb') as out_file:
    out_csv = csv.writer(out_file,
                         delimiter=',',
                         quotechar='"',
                         quoting=csv.QUOTE_MINIMAL)
    out_csv.writerow(['network', 'start_addr', 'end_addr', 'option', 'value'])
    for info in discovered_options:
        out_csv.writerow(info)

This program produces a CSV file 'ranges-with-option.csv' that has the following format:

network,start_addr,end_addr,option,value

192.168.201.0/24,192.168.201.100,192.168.201.148,7,"192.168.201.200,192.168.201.201"?

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.