Skip to content

Instantly share code, notes, and snippets.

@cetinajero
Created June 19, 2023 17:39
Show Gist options
  • Save cetinajero/4e7b4b663a9a073e9fe60d3ab32a8204 to your computer and use it in GitHub Desktop.
Save cetinajero/4e7b4b663a9a073e9fe60d3ab32a8204 to your computer and use it in GitHub Desktop.
Private alternative to DynDns and, thanks to Cloudflare, completely free.

Manage access and permissions for your accounts, sites, and products.

Token name

  • Netguard 3.0 (curl)

Permissions

  • Zone - DNS - Edit

Zone Resources

  • Include - Specific Zone - grupopv.mx

Client IP Address Filtering

  • Is in - 189.178.0.0/16, 201.174.104.210

List the zones to get the zone ID.

curl --ipv4 -H "Authorization: Bearer K-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type:application/json" -X GET "https://api.cloudflare.com/client/v4/zones/" ; echo

Create a new DNS record for a zone.

curl --ipv4 -H "Authorization: Bearer K-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type:application/json" -X POST "https://api.cloudflare.com/client/v4/zones/7f95fa1d6b62c55ccf84ad1980911825/dns_records" --data '{"type":"A","name":"fg.gdl","content":"127.0.0.1","ttl":60,"proxied":false}' ; echo

Patch the DNS record for a zone.

curl --ipv4 -H "Authorization: Bearer K-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type:application/json" -X PATCH "https://api.cloudflare.com/client/v4/zones/7f95fa1d6b62c55ccf84ad1980911825/dns_records/bf0a355e85afc458ce968abefb066c75" --data '{"content":"127.0.0.127"}' ; echo

Patch the DNS record with the current public IP.

curl --ipv4 -H "Authorization: Bearer K-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type:application/json" -X PATCH "https://api.cloudflare.com/client/v4/zones/7f95fa1d6b62c55ccf84ad1980911825/dns_records/bf0a355e85afc458ce968abefb066c75" --data '{"content":"'$(curl checkip.amazonaws.com)'"}' ; echo

Crontab: ev3.nit.mx

*/2 * * * * curl --ipv4 -X PATCH -H Content-Type:application/json -H "Authorization: Bearer K-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" --data '{"content":"'$(curl checkip.amazonaws.com)'"}' https://api.cloudflare.com/client/v4/zones/a4a18e894753cce26d07e26ef473d2ab/dns_records/c41475b8603d330ab4d9b5eba3e5349a

Windows: fg.gdl.grupopv.mx:444

schtasks /create /tn "Netguard 3.0" /tr "%userprofile%\projects\batch\netguard\app.vbs" /sc minute /mo 2
  • projects\batch\netguard\app.vbs
Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run """%userprofile%\projects\batch\netguard\app.bat""", 0 , false
  • projects\batch\netguard\app.bat
@echo off
cd %userprofile%\projects\batch\netguard
curl checkip.amazonaws.com > public_ip.tmp
set /p public_ip= < public_ip.tmp
del public_ip.tmp
curl --ipv4 -X PATCH -H Content-Type:application/json -H "Authorization: Bearer K-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" --data "{\"content\":\"%public_ip%\"}" https://api.cloudflare.com/client/v4/zones/7f95fa1d6b62c55ccf84ad1980911825/dns_records/bf0a355e85afc458ce968abefb066c75
echo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment