Created
February 19, 2025 22:00
-
-
Save willwade/251fa791da27267b5470c75a7b55ff45 to your computer and use it in GitHub Desktop.
Toggle NextDNS deny domain
This file contains 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
#!/bin/bash | |
# Configuration - Replace with your actual API key and Profile ID | |
API_KEY="apikey" | |
PROFILE_ID="id" | |
DOMAIN="youtube.com" | |
# Function to get current block status | |
get_status() { | |
curl -s -X GET "https://api.nextdns.io/profiles/$PROFILE_ID/denylist" \ | |
-H "X-Api-Key: $API_KEY" | jq -r ".denylist[] | select(.id==\"$DOMAIN\") | .active" | |
} | |
# Get current status | |
STATUS=$(get_status) | |
if [[ "$STATUS" == "true" ]]; then | |
echo "YouTube is currently BLOCKED. Unblocking..." | |
NEW_STATUS="false" | |
elif [[ "$STATUS" == "false" ]]; then | |
echo "YouTube is currently ALLOWED. Blocking..." | |
NEW_STATUS="true" | |
else | |
echo "YouTube is NOT in the denylist. Blocking..." | |
NEW_STATUS="true" | |
fi | |
# Toggle the status | |
curl -X POST "https://api.nextdns.io/profiles/$PROFILE_ID/denylist" \ | |
-H "Content-Type: application/json" \ | |
-H "X-Api-Key: $API_KEY" \ | |
-d "{\"id\": \"$DOMAIN\", \"active\": $NEW_STATUS}" | |
# Confirm new status | |
UPDATED_STATUS=$(get_status) | |
if [[ "$UPDATED_STATUS" == "true" ]]; then | |
echo "✅ YouTube is now BLOCKED." | |
elif [[ "$UPDATED_STATUS" == "false" ]]; then | |
echo "✅ YouTube is now ALLOWED." | |
else | |
echo "⚠️ Something went wrong. Please check manually." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment