Reply

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

Adviser
Posts: 69
3187     0

Hi,

 

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 https://10.192.33.220/wapi/v2.7/record:host -d '{ "name": "b.test.com", "ipv4addrs": [{ "ipv4addr": "func:nextavailablep:10.192.32.0/24" }], "extattrs": { "Building": {"value": "building1"}} }'

 

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

 

image.png

 

 

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

 

Regards,

Sandeep

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

Adviser
Posts: 69
3187     0

Hi,

 

Sorry about the delayed response.

 

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

 

#!/usr/bin/python

import requests, json


from requests.auth import HTTPBasicAuth
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)



url = 'https://10.192.33.220/wapi/v2.7/record:host'
newhost = raw_input("Enter hostname: ")
network = raw_input("Enter network in the format 192.168.0.0/24: ")
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 = requests.post(url, 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
else:
	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 host.py
Enter hostname: testing.test.com
Enter network in the format 192.168.0.0/24: 10.192.32.0/24
Enter value for extensible attribute 'Building': east-building
Host record created successfully.
[
    {
        "_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS50ZXN0LnRlc3Rpbmc:testing.test.com/default",
        "ipv4addrs": [
            {
                "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLnRlc3QudGVzdGluZy4xMC4xOTIuMzIuMTQu:10.192.32.14/testing.test.com/default",
                "configure_for_dhcp": false,
                "host": "testing.test.com",
                "ipv4addr": "10.192.32.14"
            }
        ],
        "name": "testing.test.com",
        "view": "default"
    }
]

 

 

Hope this is helpful. 

 

Sandeep

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