58 lines
2.4 KiB
Bash
58 lines
2.4 KiB
Bash
#!/bin/bash
|
|
|
|
echo -e "
|
|
░█████╗░███╗░░██╗██████╗░██████╗░░█████╗░░██████╗
|
|
██╔══██╗████╗░██║██╔══██╗██╔══██╗██╔══██╗██╔════╝
|
|
███████║██╔██╗██║██║░░██║██║░░██║██║░░██║╚█████╗░
|
|
██╔══██║██║╚████║██║░░██║██║░░██║██║░░██║░╚═══██╗
|
|
██║░░██║██║░╚███║██████╔╝██████╔╝╚█████╔╝██████╔╝
|
|
╚═╝░░╚═╝╚═╝░░╚══╝╚═════╝░╚═════╝░░╚════╝░╚═════╝░"
|
|
|
|
|
|
COUNTRIES="af es"
|
|
|
|
for country in $COUNTRIES; do
|
|
url="https://www.ipdeny.com/ipblocks/data/countries/${country}.zone"
|
|
echo "Tentando baixar lista de IPs para o país: $country"
|
|
|
|
tmp_file="${country}.zone.tmp"
|
|
target_file="${country}.zone"
|
|
|
|
if curl -sSf -o "$tmp_file" "$url"; then
|
|
echo "Download concluído para $country."
|
|
|
|
if [ -f "$target_file" ]; then
|
|
if cmp -s "$tmp_file" "$target_file"; then
|
|
echo "Arquivo para $country não mudou. Mantendo versão atual."
|
|
rm "$tmp_file"
|
|
else
|
|
echo "Arquivo para $country mudou. Atualizando..."
|
|
mv "$tmp_file" "$target_file"
|
|
fi
|
|
else
|
|
echo "Arquivo para $country não existia. Salvando novo arquivo."
|
|
mv "$tmp_file" "$target_file"
|
|
fi
|
|
else
|
|
echo "Falha no download do arquivo para $country. Mantendo versão antiga (se existir)."
|
|
[ -f "$tmp_file" ] && rm "$tmp_file"
|
|
continue
|
|
fi
|
|
|
|
# Verifica se ipset existe
|
|
if ipset list "$country" > /dev/null 2>&1; then
|
|
echo "IpSet '$country' já existe. Limpando entradas antigas..."
|
|
ipset flush "$country"
|
|
else
|
|
echo "Criando IpSet '$country'."
|
|
ipset create "$country" hash:net
|
|
fi
|
|
|
|
# Adicionar cada rede ao ipset
|
|
while read -r subnet; do
|
|
ipset add "$country" "$subnet" -exist
|
|
done < "$target_file"
|
|
|
|
echo "Concluído para o país $country."
|
|
done
|