-
-
Save stream2me/7e825e7ff21714e8023a847944118475 to your computer and use it in GitHub Desktop.
Update Cloudflare Access Group IP address based on current public IP address from the requestor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ACCOUNT_ID="YOUR_ACCOUNT_ID" | |
| GROUP_ID="YOUR_ACCESS_GROUP_ID" | |
| GROUP_NAME="YOUR_ACCESS_GROUP_NAME" | |
| API_TOKEN="YOUR_CLOUDFLARE_API_KEY" | |
| IP_ADDRESS=$(curl -s https://api.ipify.org) | |
| OLD_IP=$(curl -s \ | |
| --request GET \ | |
| --url https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/access/groups/$GROUP_ID \ | |
| --header 'Content-Type: application/json' \ | |
| --header "Authorization: Bearer $API_TOKEN" \ | |
| | grep '"ip": "' | cut -b18-31) | |
| if [ "$OLD_IP" = "$IP_ADDRESS" ]; then | |
| echo "Address is still: $OLD_IP" | |
| else | |
| echo "IP changed..." | |
| curl -s -o /dev/null \ | |
| --request PUT \ | |
| --url https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/access/groups/$GROUP_ID \ | |
| --header 'Content-Type: application/json' \ | |
| --header "Authorization: Bearer $API_TOKEN" \ | |
| --data '{ | |
| "include": [ | |
| { | |
| "ip": { | |
| "ip": "'"$IP_ADDRESS"'" | |
| } | |
| } | |
| ], | |
| "name": "'"$GROUP_NAME"'" | |
| }' | |
| echo "Updated $GROUP_NAME to include $IP_ADDRESS" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment