import requests
# Cloudflare API details
api_token = 'cloudflare_api_token' # Your actual token
zone_id = 'cloudflare_zone_id' # Your actual zone ID
# IP addresses to whitelist
ip_addresses = [
"104.238.152.43", "108.61.241.142", "116.202.19.127", "116.202.19.155",
"116.203.118.7", "116.203.132.27", "116.203.198.39", "116.203.233.120",
"116.203.239.26", "116.203.34.150", "116.203.51.60", "116.203.78.154",
"116.203.83.180", "128.140.106.217", "128.140.113.7", "128.140.114.147",
"135.181.47.119", "135.181.47.53", "135.181.85.71", "136.244.99.211",
"142.132.225.96", "149.248.51.165", "149.28.168.226", "149.28.70.57",
"154.38.188.63", "154.38.188.70", "154.38.188.71", "155.133.7.189",
"155.133.7.190", "155.133.7.191", "162.55.37.127", "167.235.31.59",
"167.235.31.61", "167.235.50.149", "168.119.98.26", "188.138.88.128",
"195.201.114.80", "195.201.33.39", "207.148.11.143", "209.126.105.183",
"213.32.156.56", "216.238.105.167", "216.238.73.19", "217.172.182.99",
"23.88.103.18", "23.88.127.150", "23.88.37.51", "23.88.44.194",
"31.220.100.234", "31.220.100.243", "31.220.101.1", "31.220.101.4",
"31.220.103.140", "31.220.103.141", "31.220.103.142", "31.220.103.143",
"31.220.103.144", "31.220.103.145", "31.220.103.146", "31.220.103.147",
"45.32.132.233", "45.63.109.119", "45.76.111.202", "45.77.38.130",
"45.77.98.111", "46.250.254.91", "46.250.254.92", "49.12.110.221",
"49.12.35.156", "49.12.9.143", "49.13.136.104", "49.13.201.151",
"49.13.87.186", "5.104.80.101", "5.104.80.118", "5.104.81.110",
"5.161.124.144", "5.161.186.44", "5.161.189.249", "5.161.196.124",
"5.161.41.211", "5.161.75.231", "5.161.78.57", "5.161.84.202",
"5.161.86.62", "5.75.132.49", "5.75.179.145", "5.75.255.64",
"62.75.216.18", "66.42.93.216", "69.64.52.37", "70.34.203.153",
"78.141.232.8", "78.46.206.34", "78.46.208.48", "78.47.112.255",
"78.47.154.90", "78.47.205.130", "84.247.154.4", "84.247.154.5",
"85.25.117.18", "85.25.208.97", "85.25.226.85", "95.179.220.67",
"95.217.235.103"
]
# Cloudflare API endpoint
url = "https://api.cloudflare.com/client/v4/zones/{}/firewall/access_rules/rules".format(zone_id)
headers = {
"Authorization": "Bearer {}".format(api_token),
"Content-Type": "application/json"
}
for ip in ip_addresses:
data = {
"mode": "whitelist",
"configuration": {
"target": "ip",
"value": ip
},
"notes": "Monitoring360 Service"
}
response = requests.post(url, headers=headers, json=data)
print(f"Request data for IP {ip}: {data}")
print(f"Response: {response.status_code} - {response.json()}")
if response.status_code == 200:
print("Successfully whitelisted {}".format(ip))
else:
print("Failed to whitelist {}: {}".format(ip, response.json()))