-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathblockad-cn
31 lines (24 loc) · 1.09 KB
/
blockad-cn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/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