List api with multiple ips

CloudFlare api list help
#!/bin/bash

MY_IP=$(curl https://ifconfig.me/ip) # ideally radar.cloudflare.com/ip but dont support

AUTH_KEY="###"
AUTH_EMAIL="###"
API_ACCOUNT_ID="###"
API_LIST_ID="###"
API_ENDPOINT="https://api.cloudflare.com/client/v4/accounts/$API_ACCOUNT_ID/rules/lists/$API_LIST_ID/items"

curl -X PUT "$API_ENDPOINT" \
-H "X-Auth-Email: $AUTH_EMAIL" \
-H "X-Auth-Key: $AUTH_KEY" \
-H "Content-Type: application/json" \
--data "[{\"ip\":\"$MY_IP\"}]"
#!/bin/bash

MY_IP=$(curl https://ifconfig.me/ip) # ideally radar.cloudflare.com/ip but dont support

AUTH_KEY="###"
AUTH_EMAIL="###"
API_ACCOUNT_ID="###"
API_LIST_ID="###"
API_ENDPOINT="https://api.cloudflare.com/client/v4/accounts/$API_ACCOUNT_ID/rules/lists/$API_LIST_ID/items"

curl -X PUT "$API_ENDPOINT" \
-H "X-Auth-Email: $AUTH_EMAIL" \
-H "X-Auth-Key: $AUTH_KEY" \
-H "Content-Type: application/json" \
--data "[{\"ip\":\"$MY_IP\"}]"
bash list-whitelist-ip.sh
3 Replies
:) EpickyHrac
:) EpickyHracOP8mo ago
Work with single ip but how to add to a list multiple ips? Please example for ipv4 and ipv6. Original message from #List Api Help pls
Akama Aka
Akama Aka8mo ago
Uhhh for loop? Something like that I guess
# Get CloudFlare IPs from CloudFlare API
## Save the response from the CloudFlare IP into a Variable called "response"
response=$(curl --request GET --url https://api.cloudflare.com/client/v4/ips)

## Get the response Variable and echo it into the ipv4 Variable but just that from the result > ipv4_cidrs[] array
ipv4=$(echo $response | jq -r '.result.ipv4_cidrs[]')
## Get the response Variable and echo it into the ipv6 Variable but just that from the result > ipv6_cidrs[] array
ipv6=$(echo $response | jq -r '.result.ipv6_cidrs[]')

## Set the default Firewall Zone to DMZ
firewall-cmd --permanent --set-default-zone=dmz

## Create a new ipset called "Cloudflarev4".
firewall-cmd --permanent --new-ipset=Cloudflarev4 --type=hash:net

## Loop trough all CloudFlare IPs
echo "$ipv4" | while read ip; do
## And add it into the Cloudflarev4 ipset.
firewall-cmd --permanent --ipset=Cloudflarev4 --add-entry="$ip"
done
# Get CloudFlare IPs from CloudFlare API
## Save the response from the CloudFlare IP into a Variable called "response"
response=$(curl --request GET --url https://api.cloudflare.com/client/v4/ips)

## Get the response Variable and echo it into the ipv4 Variable but just that from the result > ipv4_cidrs[] array
ipv4=$(echo $response | jq -r '.result.ipv4_cidrs[]')
## Get the response Variable and echo it into the ipv6 Variable but just that from the result > ipv6_cidrs[] array
ipv6=$(echo $response | jq -r '.result.ipv6_cidrs[]')

## Set the default Firewall Zone to DMZ
firewall-cmd --permanent --set-default-zone=dmz

## Create a new ipset called "Cloudflarev4".
firewall-cmd --permanent --new-ipset=Cloudflarev4 --type=hash:net

## Loop trough all CloudFlare IPs
echo "$ipv4" | while read ip; do
## And add it into the Cloudflarev4 ipset.
firewall-cmd --permanent --ipset=Cloudflarev4 --add-entry="$ip"
done
:) EpickyHrac
:) EpickyHracOP8mo ago
I got it
#!/bin/bash

MY_IPS=($(curl -s https://ifconfig.me/ip) "1.1.1.1")

IPS_JSON=""
for ip in "${MY_IPS[@]}"; do
IPS_JSON+="{\"ip\":\"$ip\"},"
done
IPS_JSON="${IPS_JSON%,}"
curl -X PUT "$API_ENDPOINT" \
-H "X-Auth-Email: $AUTH_EMAIL" \
-H "X-Auth-Key: $AUTH_KEY" \
-H "Content-Type: application/json" \
--data "[$IPS_JSON]"
#!/bin/bash

MY_IPS=($(curl -s https://ifconfig.me/ip) "1.1.1.1")

IPS_JSON=""
for ip in "${MY_IPS[@]}"; do
IPS_JSON+="{\"ip\":\"$ip\"},"
done
IPS_JSON="${IPS_JSON%,}"
curl -X PUT "$API_ENDPOINT" \
-H "X-Auth-Email: $AUTH_EMAIL" \
-H "X-Auth-Key: $AUTH_KEY" \
-H "Content-Type: application/json" \
--data "[$IPS_JSON]"
Want results from more Discord servers?
Add your server