2019-07-24 17:35:39 +02:00
|
|
|
#!/usr/bin/env python3
|
2020-07-21 00:31:06 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-07-24 17:35:39 +02:00
|
|
|
|
2020-07-27 10:44:30 +02:00
|
|
|
from generator import download_to_file, get_version, write_to_file, get_abspath_source_file
|
2020-07-17 10:06:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def process(files, dst):
|
2020-07-21 00:31:06 +02:00
|
|
|
warninglist = {
|
|
|
|
'name': "List of known Cloudflare IP ranges",
|
|
|
|
'version': get_version(),
|
|
|
|
'description': "List of known Cloudflare IP ranges (https://www.cloudflare.com/ips/)",
|
|
|
|
'type': "cidr",
|
|
|
|
'list': [],
|
2024-04-22 09:20:14 +02:00
|
|
|
'matching_attributes': ["ip-src", "ip-dst", "domain|ip", "ip-src|port", "ip-dst|port"]
|
2020-07-21 00:31:06 +02:00
|
|
|
}
|
2020-07-17 12:42:34 +02:00
|
|
|
|
2020-07-17 10:06:06 +02:00
|
|
|
for file in files:
|
2020-07-27 10:44:30 +02:00
|
|
|
with open(get_abspath_source_file(file), 'r') as f:
|
2020-07-17 10:06:06 +02:00
|
|
|
ips = f.readlines()
|
|
|
|
for ip in ips:
|
|
|
|
warninglist['list'].append(ip.strip())
|
2020-07-17 12:42:34 +02:00
|
|
|
|
2020-07-21 00:31:06 +02:00
|
|
|
write_to_file(warninglist, dst)
|
2020-07-17 10:06:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
cf_base_url = "https://www.cloudflare.com/"
|
2020-07-17 12:42:34 +02:00
|
|
|
uri_list = ['ips-v4', 'ips-v6']
|
2020-07-17 10:06:06 +02:00
|
|
|
cf_dst = 'cloudflare'
|
|
|
|
|
|
|
|
to_process = list()
|
|
|
|
|
|
|
|
for uri in uri_list:
|
|
|
|
url = cf_base_url+uri
|
|
|
|
file = 'cloudflare_{}.txt'.format(uri)
|
|
|
|
download_to_file(url, file)
|
|
|
|
to_process.append(file)
|
2020-07-17 12:42:34 +02:00
|
|
|
|
2020-07-17 10:06:06 +02:00
|
|
|
process(to_process, cf_dst)
|