Skip to content

Instantly share code, notes, and snippets.

@venam
Created July 12, 2018 04:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save venam/97a06e563161693d109b9d31152bab0b to your computer and use it in GitHub Desktop.
Save venam/97a06e563161693d109b9d31152bab0b to your computer and use it in GitHub Desktop.
hosts block autofetcher
#!/bin/bash
# fetch the new block list
wget 'https://v.firebog.net/hosts/lists.php?type=all' -O list_all
# reset the old hosts directory
rm -r all_hosts
mkdir all_hosts
# read the file and download into the all_hosts directory
while read a; do
wget -P all_hosts "$a"
done < list_all
# fill the all_blocks file with the fixed up lines of all the hosts files
rm all_blocks
for a in $(command ls -1 all_hosts); do
sed -f fix_host.sed "all_hosts/$a" >> all_blocks
done
# sort and uniq it
sed -f fix_host.sed all_blocks | sort | uniq > all_blocks.uniq
mv all_blocks.uniq all_blocks
/^#/d
/^\s*$/d
s/\s\+/ /g
s/0.0.0.0/127.0.0.1/
/^127.0.0.1/!d
s/[ \t]*$//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment