Skip to content

Commit a0a95c6

Browse files
committed
produce a list from aws zones
1 parent 0bfd73b commit a0a95c6

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

aws_get_domains.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
3+
import boto3
4+
import pprint
5+
6+
boto3.setup_default_session(profile_name='default')
7+
"""
8+
this profile should be a [block] in ~/.aws/credentials
9+
"""
10+
11+
domain_list = []
12+
output_path = 'domains.txt'
13+
write_things = open(output_path, 'w')
14+
15+
client = boto3.client('route53')
16+
17+
18+
def prettyfy(things):
19+
"""
20+
prettyfy any dict/list thing
21+
"""
22+
pp = pprint.PrettyPrinter(indent=4)
23+
return pp.pprint(things)
24+
25+
26+
def check_record_types(record_type):
27+
"""
28+
check if record type is interesting.
29+
"""
30+
return record_type in ('A', 'CNAME', 'AAAA')
31+
32+
33+
def list_domains(zone_id):
34+
"""
35+
accept zone id and return list of domains
36+
"""
37+
result = client.list_resource_record_sets(HostedZoneId=zone_id)
38+
records = result['ResourceRecordSets']
39+
for element in records:
40+
if check_record_types(element['Type']):
41+
domain = element['Name'].strip('.')
42+
write_things.write(str(domain) + '\n')
43+
write_things.flush()
44+
domain_list.append(domain)
45+
46+
47+
def list_zones():
48+
"""
49+
get all zones and Ids for the account
50+
"""
51+
result = client.list_hosted_zones()
52+
zones = []
53+
for zone in result['HostedZones']:
54+
zone_data = {"Domain": zone['Name'], "Id": zone['Id']}
55+
list_domains(zone['Id'])
56+
57+
58+
def main():
59+
list_zones()
60+
print(domain_list)
61+
write_things.close()
62+
63+
64+
main()

0 commit comments

Comments
 (0)