diff --git a/README.md b/README.md index 475010b..62b0f5e 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ This project is **WORK IN PROGRESS**. autodns zone-info --zone +## Find wildcard records + + autodns find-wildcard-records + ## Copyright Copyright 2018 Oliver Siegmar diff --git a/autodnscli/IpFinder.py b/autodnscli/IpFinder.py new file mode 100644 index 0000000..1a71b94 --- /dev/null +++ b/autodnscli/IpFinder.py @@ -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()) + diff --git a/autodnscli/WildcardFinder.py b/autodnscli/WildcardFinder.py new file mode 100644 index 0000000..d08f5e4 --- /dev/null +++ b/autodnscli/WildcardFinder.py @@ -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()) + diff --git a/autodnscli/ZoneInfo.py b/autodnscli/ZoneInfo.py index a4744fc..834c49a 100644 --- a/autodnscli/ZoneInfo.py +++ b/autodnscli/ZoneInfo.py @@ -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') @@ -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': diff --git a/autodnscli/autodns.py b/autodnscli/autodns.py index 4f86117..c9664a1 100755 --- a/autodnscli/autodns.py +++ b/autodnscli/autodns.py @@ -20,6 +20,8 @@ from ApiClient import ApiClient from ZoneInfo import ZoneInfo from ZoneList import ZoneList +from IpFinder import IpFinder +from WildcardFinder import WildcardFinder def main(): @@ -27,6 +29,8 @@ def main(): 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'], @@ -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)