2014-08-08 11:39:38 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-05-24 10:44:38 -04:00
|
|
|
[[ -z "$1" || -z "$2" ]] && {
|
|
|
|
printf '%s\n' 'Error: Run this scrip with a blocklist URL in p2p format and an output file as arguments' >&2
|
2014-08-08 11:39:38 -04:00
|
|
|
exit 1
|
2017-05-24 10:44:38 -04:00
|
|
|
}
|
2014-08-08 11:39:38 -04:00
|
|
|
|
2017-05-24 10:44:38 -04:00
|
|
|
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]*$")
|
2014-08-08 11:39:38 -04:00
|
|
|
|
2017-05-24 10:44:38 -04:00
|
|
|
grep -q -E "^[0-9]*.[0-9]*.[0-9]*.[0-9]*-[0-9]*.[0-9]*.[0-9]*.[0-9]*$" <<< "$p2plist" || {
|
|
|
|
printf '%s\n' "Error: The URL $1 does not appear to contain a P2P-formatted blocklist" >&2
|
|
|
|
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")
|
2014-08-08 11:39:38 -04:00
|
|
|
|
2017-05-24 10:44:38 -04:00
|
|
|
printf '%s\n' "127.0.0.1 ${ip1_1}.${ip1_2}.${ip1_3}.${ip1_4}" >> "$2"
|
2014-08-08 11:39:38 -04:00
|
|
|
|
2017-05-24 10:44:38 -04:00
|
|
|
while [[ ! "${ip1_1}.${ip1_2}.${ip1_3}.${ip1_4}" = "$ip2" ]]; do
|
|
|
|
if (( ip1_4 < 255 )); then
|
|
|
|
ip1_4=$(( ip1_4 + 1 ))
|
2014-08-08 11:39:38 -04:00
|
|
|
else
|
2017-05-24 10:44:38 -04:00
|
|
|
ip1_4=0
|
|
|
|
|
|
|
|
if (( ip1_3 < 255 )); then
|
|
|
|
ip1_3=$(( ip1_3 + 1 ))
|
2014-08-08 11:39:38 -04:00
|
|
|
else
|
2017-05-24 10:44:38 -04:00
|
|
|
ip1_3=0
|
|
|
|
|
|
|
|
if (( ip1_2 < 255 )); then
|
|
|
|
ip1_2=$(( ip1_2 + 1 ))
|
2014-08-08 11:39:38 -04:00
|
|
|
else
|
2017-05-24 10:44:38 -04:00
|
|
|
ip1_2=0
|
|
|
|
|
|
|
|
if (( ip1_1 < 255 )); then
|
|
|
|
ip1_1=$(( ip1_1 + 1 ))
|
2014-08-08 11:39:38 -04:00
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2017-05-24 10:44:38 -04:00
|
|
|
|
|
|
|
printf '%s\n' "127.0.0.1 ${ip1_1}.${ip1_2}.${ip1_3}.${ip1_4}" >> "$2"
|
2014-08-08 11:39:38 -04:00
|
|
|
done
|
|
|
|
done
|