Skip to content

Instantly share code, notes, and snippets.

@willwade
Created February 19, 2025 22:00
Show Gist options
  • Save willwade/251fa791da27267b5470c75a7b55ff45 to your computer and use it in GitHub Desktop.
Save willwade/251fa791da27267b5470c75a7b55ff45 to your computer and use it in GitHub Desktop.
Toggle NextDNS deny domain
#!/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