1. Home
  2. Tips & Tricks
  3. Bulk Upload a Subnet to CleanBrowsing

Bulk Upload a Subnet to CleanBrowsing

The easiest way to bulk upload a subnet to CleanBrowsing is to use our API.

You want to use the Network/Add action:

NETWORK/add
Adds a new IP address to your network list.

Action: network/add
Required value: ip_address=(valid_ipv4)
Optional value: profile_name=(valid_profile_name) or "default" when not provided, label=[a-zA-Z 0-9] (label for this network)
Results: {"status" = "success"};
In case of error: {"status":"failed", "reason":"reason why"}

https://my.cleanbrowsing.org/api?apikey=[key]&action=network/add&ip_address=<IPv4>&profile_name=<name>&label=<label>

To help automate this, you can use Python (Python3) if on a MacOS.

Upload /24 Using the CleanBrowsing API

Here is what you would do to upload a /24 using the CleanBrowsing API:

Step 1. Create a Python file:

cleanbrowsing-upload.py

Step 2. Paste the following script into the new file:

import ipaddress
import requests

def generate_ips(ip_range):
    ip_network = ipaddress.ip_network(ip_range, strict=False)
    return [str(ip) for ip in ip_network]

def add_ip_to_network(api_key, ip_address, profile_name="default", label=None):
    base_url = "https://my.cleanbrowsing.org/api"
    action_url = f"{base_url}?apikey={api_key}&action=network/add"

    payload = {
        "ip_address": ip_address,
        "profile_name": profile_name,
        "label": label
    }

    response = requests.get(action_url, params=payload)
    return response.text

# Replace 'your_api_key' with your actual API key
api_key = "your_api_key"
ip_range = "1.2.3.0/24"
ips = generate_ips(ip_range)

for ip in ips:
    response_text = add_ip_to_network(api_key, ip)
    print(f"Added IP {ip} to network. Response: {response_text}")

3. Update ‘your_api_key’ with the key issued in your dashboard;

4. Update ‘ip_range’ with the range and slash you want to extrapolate.

5. Run the new python file:

python3 cleanbrowsing-upload.py

6. This should output something like this:

Added IP 1.2.3.247 to network. Response: {"status":"success", "notice":"New IP Address added to your account: 1.2.3.247"}

Added IP 1.2.3.248 to network. Response: {"status":"success", "notice":"New IP Address added to your account: 1.2.3.248"}

Added IP 1.2.3.249 to network. Response: {"status":"success", "notice":"New IP Address added to your account: 1.2.3.249"}
Updated on October 21, 2024
Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support