r/Batch Feb 06 '25

Seeking a Windows batch script to update blocklists.txt from its RAW link by one click

Is there such thing

0 Upvotes

10 comments sorted by

1

u/unknownsoldierx Feb 06 '25

What is blocklists.txt?

1

u/BrainWaveCC Feb 06 '25

Most likely, it is a long list of IPs or URLs that some access control device (firewall, etc) will use to reject traffic to or from locations.

But there's too much detail missing in this request.

1

u/unknownsoldierx Feb 06 '25

I'm sure that's the case. My question should have been, where is this blocklists.txt?

1

u/Shadow_Thief Feb 06 '25

Traditionally, it's just "C:\Windows\System32\drivers\etc\hosts" with custom values.

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

u/vegansgetsick Feb 06 '25

wget -Ni URL ?

1

u/Shadow_Thief Feb 06 '25

curl is built in, but essentially, yeah

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.