{"id":920,"date":"2022-01-22T18:24:48","date_gmt":"2022-01-22T18:24:48","guid":{"rendered":"https:\/\/www.geekmungus.co.uk\/?p=920"},"modified":"2022-11-05T10:53:18","modified_gmt":"2022-11-05T10:53:18","slug":"create-or-update-txt-record-in-infoblox-api-using-python-libraries","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=920","title":{"rendered":"Create or Update TXT Record in InfoBlox API using Python Libraries"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/sifbaksh.com\/introduction-to-infoblox-api-wapi-using-python\/\">https:\/\/sifbaksh.com\/introduction-to-infoblox-api-wapi-using-python\/<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The easiest approach is to use the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/infobloxopen\/infoblox-client\" data-type=\"URL\" data-id=\"https:\/\/github.com\/infobloxopen\/infoblox-client\" target=\"_blank\">InfoBlox-Client<\/a> library in Python, it is possible to use &#8220;requests&#8221; and then parse the output, but this approach seems a bit more straightforward.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"InfoBloxDNSAddingSPF,DMARCandDKIMRecordstoEmailDomains(Automated\/CLI)-SetupvirtualenvandInstallInfoBloxModules\">Setup virtualenv and Install InfoBlox Modules<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The below assumes you already have Python 2.7 (or above) and VirtualEnv installed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\nmkdir venv\ncd venv\nvirtualenv infoblox\nsource \/home\/&lt;username>\/venv\/infoblox\/bin\/activate<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now install the infoblox-client Python modules into your Virtual Environment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install infoblox-client<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can now use the library in your scripts, see the script: <a href=\"https:\/\/github.com\/tristanhself\/general\/blob\/6939e27031e6d8343497d4f42f403a818fcfbd30\/infoblox\/infobloxapi_create_txt_record.py\" data-type=\"URL\" data-id=\"https:\/\/github.com\/tristanhself\/general\/blob\/6939e27031e6d8343497d4f42f403a818fcfbd30\/infoblox\/infobloxapi_create_txt_record.py\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/tristanhself\/general\/blob\/6939e27031e6d8343497d4f42f403a818fcfbd30\/infoblox\/infobloxapi_create_txt_record.py<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Creating a DMARC or SPF Record Using the Script<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To use the script you can pass arguments, these as follows:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-e = Endpoint FQDN of your InfoBlox appliance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-u and -p = Username and Password of a user with rights to CRUD objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-c = Create if exists, set to &#8220;True&#8221; or &#8220;False&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-x = Update if exists, set to &#8220;True&#8221; or &#8220;False&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-v = The view, if you run split DNS, you may have multiple views, enter the relevant name here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-n = The actual DNS domain you wish to add.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-t = The text body of the TXT record.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">-o = Description (comment) of the record.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So let&#8217;s see an example to create a DMARC record:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/infobloxapi_create_txt_record.py -e infoblox1.domain.com -u &lt;username> -p &lt;password> -c True -x True -v external -n \"_dmarc.domain.com\" -t \"v=DMARC1;p=none;fo=1;rua=mailto:dmarc_rua@dmarccheck.com;ruf=mailto:dmarc_ruf@dmarccheck.com\" -o \"Email DMARC record, detailing the email domain security posture and reporting information.\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And then an example to create an SPF record:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/infobloxapi_create_txt_record.py -e infoblox1.domain.com -u &lt;username> -p &lt;password> -c True -x True -v external -n \"domain.com\" -t \"\\\"v=spf1 -all\\\"\" -o \"Email SPF record, detailing the authorised SMTP sender IP addresses for the domain.\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice the escapes on the text record itself, if you are including spaces within the record.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hopefully that script is of help to see how to use the InfoBlox API and manipulating it via the <a href=\"https:\/\/github.com\/infobloxopen\/infoblox-client\" data-type=\"URL\" data-id=\"https:\/\/github.com\/infobloxopen\/infoblox-client\" target=\"_blank\" rel=\"noreferrer noopener\">infoblox-client<\/a> Python Library.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. https:\/\/sifbaksh.com\/introduction-to-infoblox-api-wapi-using-python\/ The easiest approach is to use the InfoBlox-Client library in Python, it is possible to use &#8220;requests&#8221; and then parse the output, but this approach seems a bit &#8230; <a title=\"Create or Update TXT Record in InfoBlox API using Python Libraries\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=920\" aria-label=\"Read more about Create or Update TXT Record in InfoBlox API using Python Libraries\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":823,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,8],"tags":[],"class_list":["post-920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dns","category-infoblox"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=920"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/920\/revisions"}],"predecessor-version":[{"id":1347,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/920\/revisions\/1347"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}