misp-warninglists/tools/generate-amazon-aws.py

30 lines
831 B
Python
Raw Normal View History

2018-02-21 22:50:13 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import datetime
import urllib.request
import json
res = urllib.request.urlopen('https://ip-ranges.amazonaws.com/ip-ranges.json')
res_body = res.read()
j = json.loads(res_body.decode("utf-8"))
l = []
for prefix in j['prefixes']:
l.append(prefix['ip_prefix'])
for prefix in j['ipv6_prefixes']:
2018-02-22 10:57:31 +01:00
l.append(prefix['ipv6_prefix'])
2018-02-21 22:50:13 +01:00
warninglist = {}
warninglist['name'] = 'List of known Amazon AWS IP address ranges'
warninglist['version'] = int(datetime.date.today().strftime('%Y%m%d'))
warninglist['description'] = 'Amazon AWS IP address ranges (https://ip-ranges.amazonaws.com/ip-ranges.json)'
2018-02-22 07:53:31 +01:00
warninglist['type'] = 'cidr'
2018-02-21 22:50:13 +01:00
warninglist['list'] = sorted(set(l))
2018-02-22 07:53:31 +01:00
warninglist['matching_attributes'] = ["ip-src", "ip-dst", "domain|ip"]
2018-02-21 22:50:13 +01:00
2018-02-21 23:05:02 +01:00
print(json.dumps(warninglist))