Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (24 sloc) 1.09 KB
#!/bin/sh
# Author: https://github.com/softwaredownload/openwrt-fanqiang
# last update: 2018-10
TMP_HOSTS=/tmp/block.hosts.unsorted
HOSTS=/etc/dnsmasq.d/ad-cn.conf
# remove any old TMP_HOSTS that might have stuck around
rm ${TMP_HOSTS} 2> /dev/null
for URL in \
"https://github.com/softwaredownload/cnhosts/raw/data/_build/tmp/full/hosts" \
"https://github.com/e32ubhds/Hosts/raw/master/Hosts"
do
# filter out comment lines, empty lines, localhost...
# remove trailing comments, space( ,tab), empty line
# replace line to dnsmasq format
# remove carriage returns
# append the results to TMP_HOSTS
wget -4 --no-check-certificate -qO- "${URL}" | grep -v -e "^#" -e "^\s*$" -e "localhost" -e "broadcasthost" -e "ip6" -e "^;" -e "^@" -e "^:" -e "^[a-zA-Z]" \
| sed -E -e "s/#.*$//" -e "s/[[:space:]]*//g" -e "/^$/d" \
-e "s/^127.0.0.1/server=\/./" -e "s/0.0.0.0/server=\/./" -e "/^[0-9].*$/d" -e "s/$/\/127.0.0.0/" \
| tr -d "\r" >> ${TMP_HOSTS}
done
# remove duplicate hosts and save the real hosts file
sort ${TMP_HOSTS} | uniq > ${HOSTS}
rm ${TMP_HOSTS} 2> /dev/null
You can’t perform that action at this time.