scripts/adblock_test.sh
borekon 16a7bee6d0 dns servers converted to array
In some systems could be more than one DNS server in resolv.conf.
With this fix, we only pick the first element

Signed-off-by: borekon <alfonso@vivancos.eu>
2024-05-31 07:12:30 +00:00

30 lines
801 B
Bash

#!/bin/bash
source <(curl -s https://gitea.avc.cx/borekon/scripts/raw/branch/main/colores.sh)
ip_to_find="0.0.0.0"
blocked=0
#if [ -z "$1" ]
# then
# dns=$(cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2)
# else
# dns=$1
#fi
dns_raw=${1:-$(cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2)}
dns=($dns_raw)
domains=$(curl -s https://raw.githubusercontent.com/StevenBlack/hosts/master/data/StevenBlack/hosts | grep -v ^# | shuf -n 10 | cut -d" " -f2)
verde "Using ${dns[0]} DNS server"
for j in $domains; do
echo -e "${YELLOW}$j${NC}:"
output=$(dig -4 @${dns[0]} $j +short)
if [[ "$output" == *"$ip_to_find"* ]]; then
verde $output
((blocked++))
else
rojo $output
fi
echo ""
done;
porcentaje=$(( blocked * 10 ))
azul "$porcentaje % dominios bloqueados"