Automatic IP assignment

Posts: 2
3186     0

Hello all,


I want to assign automatically an IP according to the area/range IP :

- Find the next available IP

- Reserve the IP with DNS name and extensible attribute


Does it exist a tool/script to do this easily ?


Thank you in advance

Re: Automatic IP assignment

Posts: 69
3187     0



You could do this with a single POST request using cURL. Please see below example.



curl -k -u sr:123infobloxA -H "Content-type: application/json" -X POST -d '{ "name": "", "ipv4addrs": [{ "ipv4addr": "func:nextavailablep:" }], "extattrs": { "Building": {"value": "building1"}} }'


This will create a host record as seen in the below screenshot.





You can use the same call in a script (like using requests module in Python) to suit your environment and requirements.




Re: Automatic IP assignment

Posts: 2
3187     0

Hi Sandeep;


Thank you for your answer ! Smiley Happy


Is it possible to script the curl and display the IP reserved ?  (I don't know curl)


Thank you

Re: Automatic IP assignment

Posts: 69
3187     0



Sorry about the delayed response.


I am not very savvy on cURL. But here is a simple python script that should help.



import requests, json

from requests.auth import HTTPBasicAuth
from requests.packages.urllib3.exceptions import InsecureRequestWarning

url = ''
newhost = raw_input("Enter hostname: ")
network = raw_input("Enter network in the format ")
eavalue = raw_input("Enter value for extensible attribute 'Building': ")
nanet = "func:nextavailableip:"+network
data = json.dumps({ "name": newhost, "ipv4addrs": [{ "ipv4addr": nanet}], "extattrs": { "Building": {"value": eavalue}} })
hostrecord = json.dumps({ "name": newhost})

user = 'sr'
passwd = '123infobloxA'
header = {"content-type": "application/json"}

wapicall =, data=data, headers=header, auth=(user,passwd), verify=False)

if wapicall.status_code == 201:
	print "Host record created successfully."
	details=requests.get(url, data=hostrecord, headers=header, auth=(user,passwd), verify=False)
	print details.text
	print "Something went wrong!\n"+wapicall.text+"\n"


Here is what the output looks like.

sandeep@jarvis:/mnt/c/Users/rensa/Dropbox/Scripting/Python/test$ python
Enter hostname:
Enter network in the format
Enter value for extensible attribute 'Building': east-building
Host record created successfully.
        "_ref": "record:host/",
        "ipv4addrs": [
                "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLnRlc3QudGVzdGluZy4xMC4xOTIuMzIuMTQu:",
                "configure_for_dhcp": false,
                "host": "",
                "ipv4addr": ""
        "name": "",
        "view": "default"



Hope this is helpful. 



Showing results for 
Search instead for 
Did you mean: 

Recommended for You

Businesses are investing heavily into securing company resources from cyber-attacks form cybercrimin