How to add multiple ip addresses to block list at once


#1

Hi,

I have a list of around 1,000 ip addresses that have been used to create multiple spam accounts on our site. I’d like to set up the JavaScript challenge for all of these ip addresses. I can see how to set up the challenge for individual ip addresses, but is there a way I can easily add these 1,000 ips all at once?

Thanks.


#2

It can be done via the API. Haven’t tested this script, but something link this would probably work:

http://ebin.blog/2018/04/cloudflare-api-bash-script-to-block-ip-address-in-firewall


#4

Thanks for the link to the documentation cscharff! I used that to put together a quick python script, which I’ve added here for anyone else trying to do the same thing.

import re, sys
import requests
fhand = open ('ip_list.txt')
auth_key = '***'
auth_email ='***'
	
headers = {'X-Auth-Email': auth_email, 'X-Auth-Key': auth_key, 'Content-Type': 'application/json'}

for ip in fhand:
	data = str('{{"mode":"js_challenge","configuration":{{"target":"ip","value": "{0}"}} }}'.format(str(ip.strip())))
	r = requests.post("https://api.cloudflare.com/client/v4/zones/***/firewall/access_rules/rules",   headers=headers, data=data)
	print ip
	print r.content

#5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.