Create or Update TXT Record in InfoBlox API using Python Libraries

DNS Infoblox

A very short introduction into using Python and the InfoBlox Python libraries to interact with the REST API to give you a starting point for development.

The easiest approach is to use the InfoBlox-Client library in Python, it is possible to use “requests” and then parse the output, but this approach seems a bit more straightforward.

Setup virtualenv and Install InfoBlox Modules

The below assumes you already have Python 2.7 (or above) and VirtualEnv installed.

cd ~
mkdir venv
cd venv
virtualenv infoblox
source /home/<username>/venv/infoblox/bin/activate

Now install the infoblox-client Python modules into your Virtual Environment:

pip install infoblox-client

You can now use the library in your scripts, see the script:

Creating a DMARC or SPF Record Using the Script

To use the script you can pass arguments, these as follows:

-e = Endpoint FQDN of your InfoBlox appliance.

-u and -p = Username and Password of a user with rights to CRUD objects.

-c = Create if exists, set to “True” or “False”.

-x = Update if exists, set to “True” or “False”.

-v = The view, if you run split DNS, you may have multiple views, enter the relevant name here.

-n = The actual DNS domain you wish to add.

-t = The text body of the TXT record.

-o = Description (comment) of the record.

So let’s see an example to create a DMARC record:

./ -e -u <username> -p <password> -c True -x True -v external -n "" -t "v=DMARC1;p=none;fo=1;;" -o "Email DMARC record, detailing the email domain security posture and reporting information."

And then an example to create an SPF record:

./ -e -u <username> -p <password> -c True -x True -v external -n "" -t "\"v=spf1 -all\"" -o "Email SPF record, detailing the authorised SMTP sender IP addresses for the domain."

Notice the escapes on the text record itself, if you are including spaces within the record.

Hopefully that script is of help to see how to use the InfoBlox API and manipulating it via the infoblox-client Python Library.

Leave a Reply

Your email address will not be published. Required fields are marked *