-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_route53_rr.py
executable file
·76 lines (62 loc) · 1.78 KB
/
get_route53_rr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import boto3
from boto3.session import Session
if(len(sys.argv) != 2):
print(sys.argv[0] + ' [aws cli profile name]')
sys.exit()
try:
session = Session(profile_name=sys.argv[1])
except Exception as e:
print('\n' + 'Profile Errors: ' + str(e) + '\n')
sys.exit()
client = session.client('route53')
def get_hostedzones():
results = []
res = client.list_hosted_zones()
for lists in res['HostedZones']:
zonename = lists['Name']
if lists['Config']['PrivateZone'] is True:
private_zone = 'True'
else:
private_zone = 'False'
if not lists['Config']['Comment']:
conf_comment = ''
else:
conf_comment = lists['Config']['Comment']
zoneid = lists['Id']
results.append([zonename, private_zone, conf_comment, zoneid])
return results
def get_records(zoneid):
results = []
res = client.list_resource_record_sets(HostedZoneId=zoneid)
for lists in res['ResourceRecordSets']:
rrs = []
"""
replace char '\052' to '*'
"""
if '\\052' in lists['Name']:
rname = lists['Name'].replace('\\052', '*')
else:
rname = lists['Name']
if 'TTL' in lists:
ttl = str(lists['TTL'])
rtype = lists['Type']
if 'ResourceRecords' in lists:
for rr_values in lists['ResourceRecords']:
rrs.append(rr_values['Value'])
results.append([rname, ttl, rtype, ' '.join(rrs)])
return results
def main():
for lists in get_hostedzones():
print('\n' + '### Domain Info')
print('# DOMAIN, PrivateFlag, COMMENT, DOMAIN ID')
domain = ','.join(lists)
print(domain)
print('### RR')
print('# hostname, ttl, rrtype, values')
for lists in get_records(domain.split(',')[3]):
print(','.join(lists))
if __name__ == '__main__':
main()