Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ This project is **WORK IN PROGRESS**.
autodns zone-info --zone <zone-name>


## Find wildcard records

autodns find-wildcard-records
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autodns find-ip-records is missing


## Copyright

Copyright 2018 Oliver Siegmar
Expand Down
37 changes: 37 additions & 0 deletions autodnscli/IpFinder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import xml.etree.ElementTree as ET
import time
from ZoneInfo import ZoneInfo

class IpFinder:

def __init__(self, apiClient):
self.apiClient = apiClient

def run(self, ip):
response = self.getList()
zones = response.findall('result/data/zone')
print('Zone count: ' + str(len(zones)))
for zone in zones:
zone_name = zone.find('name').text
records = ZoneInfo(self.apiClient).run(zone_name, False)
for record in records:
if ip in record.value:
print("Zone: ", zone_name)
print(record.name)
time.sleep(1)


def getList(self):
request = self.apiClient.new_req('0205')
task = request.find('task')

view = ET.SubElement(task, 'view')

limit = ET.SubElement(view, 'limit')
limit.text = str(5000)

children = ET.SubElement(view, 'children')
children.text = '1'

return self.apiClient.call_api(ET.tostring(request).decode())

37 changes: 37 additions & 0 deletions autodnscli/WildcardFinder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import xml.etree.ElementTree as ET
import time
from ZoneInfo import ZoneInfo

class WildcardFinder:

def __init__(self, apiClient):
self.apiClient = apiClient

def run(self):
response = self.getList()
zones = response.findall('result/data/zone')
print('Zone count: ' + str(len(zones)))
for zone in zones:
zone_name = zone.find('name').text
records = ZoneInfo(self.apiClient).run(zone_name, False)
for record in records:
if record.name == '*':
print("Zone: ", zone_name)
print(record.name)
time.sleep(1)


def getList(self):
request = self.apiClient.new_req('0205')
task = request.find('task')

view = ET.SubElement(task, 'view')

limit = ET.SubElement(view, 'limit')
limit.text = str(5000)

children = ET.SubElement(view, 'children')
children.text = '1'

return self.apiClient.call_api(ET.tostring(request).decode())

17 changes: 12 additions & 5 deletions autodnscli/ZoneInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

import xml.etree.ElementTree as ET


class ZoneInfo:

def __init__(self, apiClient):
self.apiClient = apiClient

def run(self, a_zone_name):
def run(self, a_zone_name, printout=True):
request = self.apiClient.new_req('0205')
task = request.find('task')

Expand All @@ -31,16 +30,24 @@ def run(self, a_zone_name):
response = self.apiClient.call_api(ET.tostring(request).decode())

ignored_records = ['changed', 'comment', 'created', 'domainsafe', 'name', 'ns_action',
'owner', 'soa', 'system_ns', 'updated_by']
'owner', 'soa', 'system_ns', 'updated_by', 'dnssec', 'idn', 'ns_group']

record_array = []

for zone in response.findall('result/data/zone'):
ET.dump(zone)
# ET.dump(zone)
for rec in list(zone):
if rec.tag not in ignored_records:
parsed_record = self.parse_record(rec, zone)

if parsed_record is not None:
if parsed_record is None:
continue

if printout is True:
parsed_record.print_out()
else:
record_array.append(parsed_record)
return record_array

def parse_record(self, rec, zone):
if rec.tag == 'nserver':
Expand Down
8 changes: 8 additions & 0 deletions autodnscli/autodns.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
from ApiClient import ApiClient
from ZoneInfo import ZoneInfo
from ZoneList import ZoneList
from IpFinder import IpFinder
from WildcardFinder import WildcardFinder


def main():
parser = argparse.ArgumentParser()
parser.add_argument('commands', metavar='cmd', nargs='+',
help='commands to operate')
parser.add_argument('--zone')
parser.add_argument('--ip')

args = parser.parse_args()

apiClient = ApiClient(os.environ['AUTODNS_USERNAME'], os.environ['AUTODNS_PASSWORD'],
Expand All @@ -37,6 +41,10 @@ def main():
ZoneList(apiClient).run()
elif cmd == 'zone-info':
ZoneInfo(apiClient).run(args.zone)
elif cmd == 'find-wildcard-records':
WildcardFinder(apiClient).run()
elif cmd == 'find-ip-records':
IpFinder(apiClient).run(args.ip)
else:
sys.exit("Unknown command: " + cmd)

Expand Down