about summary refs log tree commit diff stats
path: root/src/instances/cloudflare_ips.py
blob: 12a1fbe9f1c176838aa6236d3974e6eeb6cbe0f8 (plain) (blame)
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
# Note: Run this script from the root of the repo

import requests
import json
import subprocess
from colorama import Fore, Back, Style

def init_cloudflare():
    r = requests.get('https://www.cloudflare.com/ips-v4')
    myList = []
    for i in r.text.split('\n'):
        out = subprocess.run(
            ["sh", "./src/instances/get_possible_ips.sh", i],
            capture_output=True,
            text=True
        )
        myList += out.stdout.splitlines()
    print(Fore.GREEN + 'Fetched ' +
          Fore.RED + 'Cloudflare IPs' +
          Style.RESET_ALL)

    return myList

cloudflare_ips = init_cloudflare()
print(cloudflare_ips)

json_object = json.dumps(cloudflare_ips, ensure_ascii=False, indent=2)
with open('./src/instances/cloudflare_ips.json', 'w') as outfile:
    outfile.write(json_object)
print(Fore.BLUE + 'wrote ' + Style.RESET_ALL + 'instances/cloudflare_ips.json')