Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # download the current Amazon AWS list of netblocks and dump it into
- # two files, one each for IPv4 and IPv6. The result can be imported
- # into firewalld ipsets using --add-entries-from-file
- import requests
- ipv4_filename = 'AmazonAWS_ipv4.zone'
- ipv6_filename = 'AmazonAWS_ipv6.zone'
- # See https://aws.amazon.com/blogs/aws/aws-ip-ranges-json/
- # fetch the JSON
- r = requests.get('https://ip-ranges.amazonaws.com/ip-ranges.json')
- # parse it into a dict of dicts
- j = r.json()
- # dump into output files
- with open(ipv4_filename, "w") as ipv4_file:
- for p in j['prefixes']:
- ipv4_file.write(p['ip_prefix'])
- ipv4_file.write('\n')
- with open(ipv6_filename, "w") as ipv6_file:
- for p in j['ipv6_prefixes']:
- ipv6_file.write(p['ipv6_prefix'])
- ipv6_file.write('\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement