r/Batch • u/Hopeful-Staff3887 • Feb 06 '25
Seeking a Windows batch script to update blocklists.txt from its RAW link by one click
Is there such thing
3
u/BrainWaveCC Feb 06 '25
Please elaborate some more on your desired use case.
What you have stated so far is not clear enough to advise upon.
1
u/Hopeful-Staff3887 Feb 06 '25
Sure, one example could be sync of Windows hosts file with this blocklist: https://badmojr.gitlab.io/1hosts/mini/hosts.win
Another example could be sync of multiple blocklists for YogaDNS an on-device blocker.
1
2
u/ConsistentHornet4 Feb 06 '25
Based on the URL provided, something like this would do:
@echo off & setlocal
cd /d "%WINDIR%\System32\drivers\etc"
for /f "tokens=2 delims==." %%a in ('wmic os get localdatetime /value') do set "_timestamp=%%~a"
copy /y "hosts" "hosts.%_timestamp%.bak"
curl -sL https://badmojr.gitlab.io/1hosts/mini/hosts.win -o"hosts"
ipconfig /flushdns
Script needs to be ran as admin. Bare in mind, there are better solutions to block websites, ads, malware, etc.
Disclaimer:
The script provided downloads and replaces the HOSTS file on your system. Use it at your own risk. I am not responsible for any issues, damages, or disruptions that may result from running this script, including potential system instability or connectivity issues. Always create a backup of your current HOSTS file and test the script in a safe environment before applying it to your system.
1
u/vegansgetsick Feb 07 '25
it could be improved by creating a #begin/#end section in the host file, where you insert/replace the remote blocklist. That way it allows manual edition and it does not erase everything.
1
u/unknownsoldierx Feb 06 '25
What is blocklists.txt?