Last active
January 13, 2025 21:05
-
-
Save aalonzolu/08a22a59fb0c9ea0528bff9122f2028c to your computer and use it in GitHub Desktop.
Export Vultr DNS records to BIND text file for importing in Cloudflare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
domain_name = 'example.com' # Change this | |
accces_token = 'API_KEY' #Change this | |
r=requests.get("https://api.vultr.com/v1/dns/records?domain="+domain_name, headers={"API-Key":accces_token,'Content-Type': 'application/json'}) | |
JSON_DATA = r.json() | |
if(r.status_code != 200): | |
print "Error: "+r.text | |
else: | |
DNS_TYPE={} | |
for item in JSON_DATA: | |
DNS_TYPE[item['type']] = [] | |
DNS_TYPE | |
for item in JSON_DATA: | |
DNS_TYPE[item['type']].append(item) | |
DNS_TYPE['MX'] | |
for dtype in DNS_TYPE: | |
print ';; '+dtype | |
for record in DNS_TYPE[dtype]: | |
if record['name'] !='': | |
record['name']= record['name']+'.' | |
if record['priority']==0: | |
print record['name']+domain_name+'.\t'+'1\t'+'IN\t'+record['type']+'\t'+record['data'] | |
else: | |
print record['name']+domain_name+'.\t'+'1\t'+'IN\t'+record['type']+'\t'+str(record['priority'])+'\t'+record['data'] |
Hey! I completely forgot I wrote this, Thanks for the Upgrade!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cheers mate!
Used this as a base for a new version using vultr 2 API. Worked for my usecase but may not be 100% accurate to the spec
Usage: