mirror of
https://github.com/prurigro/buildhosts.git
synced 2024-11-21 22:02:31 -05:00
Shortened help and added p2p to hosts conversion script
This commit is contained in:
parent
71483d6f11
commit
bf6d496e68
3 changed files with 50 additions and 2 deletions
|
@ -31,6 +31,10 @@ Build and maintain `/etc/hosts` while including lists imported from local and re
|
||||||
* `buildhosts unset`: remove lists imported from hosts list sources and restore `/etc/hosts`
|
* `buildhosts unset`: remove lists imported from hosts list sources and restore `/etc/hosts`
|
||||||
* `buildhosts help`: display the help
|
* `buildhosts help`: display the help
|
||||||
|
|
||||||
|
## Extra ##
|
||||||
|
|
||||||
|
* The `p2p-to-hosts` script included in this repo can be used to convert blocklists in p2p format to hosts format (usable with this package).
|
||||||
|
|
||||||
## Credits ##
|
## Credits ##
|
||||||
|
|
||||||
Written by Kevin MacMartin:
|
Written by Kevin MacMartin:
|
||||||
|
|
|
@ -73,8 +73,8 @@ fi
|
||||||
function buildhosts_help(){
|
function buildhosts_help(){
|
||||||
echo -e "${HEADINGCOL} ${BUILDHOSTS_SCRIPT}:${RESETCOL} build and maintain /etc/hosts with local and remote hosts list files\n${HEADINGCOL} ${RESETCOL}"
|
echo -e "${HEADINGCOL} ${BUILDHOSTS_SCRIPT}:${RESETCOL} build and maintain /etc/hosts with local and remote hosts list files\n${HEADINGCOL} ${RESETCOL}"
|
||||||
echo -e "${HEADINGCOL} commands:${RESETCOL}"
|
echo -e "${HEADINGCOL} commands:${RESETCOL}"
|
||||||
echo -e "${HEADINGCOL} ${RESETCOL}${SUCCESSCOL} ${BUILDHOSTS_SCRIPT} set:${RESETCOL} generate /etc/hosts using /etc/hosts.core and the configured sources"
|
echo -e "${HEADINGCOL} ${RESETCOL}${SUCCESSCOL} ${BUILDHOSTS_SCRIPT} set:${RESETCOL} add hosts lists to /etc/hosts"
|
||||||
echo -e "${HEADINGCOL} ${RESETCOL}${SUCCESSCOL} ${BUILDHOSTS_SCRIPT} unset:${RESETCOL} remove lists imported from hosts list sources and restore /etc/hosts"
|
echo -e "${HEADINGCOL} ${RESETCOL}${SUCCESSCOL} ${BUILDHOSTS_SCRIPT} unset:${RESETCOL} remove hosts lists from /etc/hosts"
|
||||||
echo -e "${HEADINGCOL} ${RESETCOL}${SUCCESSCOL} ${BUILDHOSTS_SCRIPT} help:${RESETCOL} display this help"
|
echo -e "${HEADINGCOL} ${RESETCOL}${SUCCESSCOL} ${BUILDHOSTS_SCRIPT} help:${RESETCOL} display this help"
|
||||||
[[ "$1" -eq 1 ]] && exit 0
|
[[ "$1" -eq 1 ]] && exit 0
|
||||||
}
|
}
|
||||||
|
|
44
p2p-to-hosts
Executable file
44
p2p-to-hosts
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
|
||||||
|
echo "Error: Run this scrip with a blocklist URL in p2p format and an output file as arguments"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
P2PLIST=$(sed 's|^.*:||' < <(wget -q -O - "$1" | gunzip) | grep -E "^[0-9]*.[0-9]*.[0-9]*.[0-9]*-[0-9]*.[0-9]*.[0-9]*.[0-9]*$")
|
||||||
|
[[ ! $(grep -E "^[0-9]*.[0-9]*.[0-9]*.[0-9]*-[0-9]*.[0-9]*.[0-9]*.[0-9]*$" <<< "$P2PLIST") ]] && echo "Error: The URL ${1} does not appear to contain a P2P-formatted blocklist" && exit 1
|
||||||
|
|
||||||
|
for address_range in ${P2PLIST[@]}; do
|
||||||
|
IP1=$(cut -d '-' -f 1 <<< "$address_range")
|
||||||
|
IP1_1=$(cut -d '.' -f 1 <<< "$IP1")
|
||||||
|
IP1_2=$(cut -d '.' -f 2 <<< "$IP1")
|
||||||
|
IP1_3=$(cut -d '.' -f 3 <<< "$IP1")
|
||||||
|
IP1_4=$(cut -d '.' -f 4 <<< "$IP1")
|
||||||
|
|
||||||
|
IP2=$(cut -d '-' -f 2 <<< "$address_range")
|
||||||
|
|
||||||
|
echo "127.0.0.1 ${IP1_1}.${IP1_2}.${IP1_3}.${IP1_4}" >> "$2"
|
||||||
|
while [ ! "${IP1_1}.${IP1_2}.${IP1_3}.${IP1_4}" = "$IP2" ]; do
|
||||||
|
if [ "$IP1_4" -lt 255 ]; then
|
||||||
|
IP1_4=$(expr $IP1_4 + 1)
|
||||||
|
else
|
||||||
|
IP1_4=0
|
||||||
|
if [ "$IP1_3" -lt 255 ]; then
|
||||||
|
IP1_3=$(expr $IP1_3 + 1)
|
||||||
|
else
|
||||||
|
IP1_3=0
|
||||||
|
if [ "$IP1_2" -lt 255 ]; then
|
||||||
|
IP1_2=$(expr $IP1_2 + 1)
|
||||||
|
else
|
||||||
|
IP1_2=0
|
||||||
|
if [ "$IP1_1" -lt 255 ]; then
|
||||||
|
IP1_1=$(expr $IP1_1 + 1)
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "127.0.0.1 ${IP1_1}.${IP1_2}.${IP1_3}.${IP1_4}" >> "$2"
|
||||||
|
done
|
||||||
|
done
|
Loading…
Reference in a new issue