This script manages automatic blocking and unblocking of TLDs (Top-Level Domains) using the NextDNS API. Blocking is activated during specific periods (days and hours) defined by environment variables. The script uses the Madrid time zone to determine when to apply or remove blocks.
Use case: I use this script to block all .com and .net domains on an AppleTV device connected to NextDNS. This is necessary because my children enjoy watching TV before going to school, and I prefer them to arrive on time :-)
-
Clone this repository:
git clone https://github.com/diegomarino/nextdns-tld-blocker.git cd nextdns-tld-blocker
-
Install dependencies:
npm install
-
Login to DigitalOcean using doctl:
doctl auth init
-
Create a new namespace for your functions (if you haven't already):
doctl serverless namespaces create your-namespace-name
-
Deploy the function:
doctl serverless deploy . --namespace your-namespace-name
-
Once deployed, you can invoke your function using:
doctl serverless functions invoke your-namespace-name/your-function-name
To use this function, you need to set up the following environment variables in your .env
file:
NEXTDNS_API_TOKEN
: Your NextDNS API tokenNEXTDNS_PROFILE_ID
: Your NextDNS profile IDBLOCKED_TLDS
: Comma-separated list of TLDs to block (default: "com,net")BLOCK_TLDS_DAYS_PERIOD
: Comma-separated start and end days for blocking period (default: "1,5" for Monday to Friday)BLOCK_TLDS_HOURS_PERIOD
: Comma-separated start and end hours for blocking period (default: "6,9" for 6 AM to 9 AM)TIMEZONE
: Timezone to use for blocking period (default: "Europe/Madrid"). Make sure to use a valid IANA timezone identifier. You can find a list of valid timezones here.
MIT