|
|
|
@ -28,8 +28,40 @@ def search_pdns(query):
|
|
|
|
|
r = requests.get(PDNS_API_BASE + 'search-data', headers={'X-API-Key': PDNS_TOKEN}, params=payload)
|
|
|
|
|
return r.json()
|
|
|
|
|
|
|
|
|
|
def set_record(zone, name, type, record):
|
|
|
|
|
payload = {
|
|
|
|
|
'rrsets': [
|
|
|
|
|
{
|
|
|
|
|
'name': name,
|
|
|
|
|
'type': type,
|
|
|
|
|
'ttl': 10800,
|
|
|
|
|
'changetype': "REPLACE",
|
|
|
|
|
'records': [ record ]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
print ('payload')
|
|
|
|
|
pprint(payload)
|
|
|
|
|
p = requests.patch(PDNS_API_BASE + 'zones/' + zone, headers={'X-API-KEY': PDNS_TOKEN}, json=payload)
|
|
|
|
|
|
|
|
|
|
print (p.text)
|
|
|
|
|
|
|
|
|
|
def pprint(text):
|
|
|
|
|
print json.dumps(text, sort_keys=True, indent=4, separators=(',', ': '))
|
|
|
|
|
|
|
|
|
|
def change_ip(record,ip):
|
|
|
|
|
record['content']=ip
|
|
|
|
|
set_record(record['zone'],record['name'],record['type'], record)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def change_records(a, b):
|
|
|
|
|
records = search_pdns(a)
|
|
|
|
|
[change_ip(record, b) for record in records]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
[pprint(result) for result in search_pdns(sys.argv[1])]
|
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
|
change_records(sys.argv[1], sys.argv[2])
|
|
|
|
|
else:
|
|
|
|
|
print('Usage:\n' + sys.argv[0] + ' from-ip to-ip')
|
|
|
|
|