This commit is contained in:
Bxio 2025-06-23 15:30:34 +01:00
parent 54faa2f6f0
commit e4e89c8e28

View File

@ -11,22 +11,46 @@ echo -e "
COUNTRIES="af es" COUNTRIES="af es"
for country in $COUNTRIES; do for country in $COUNTRIES; do
url="https://www.ipdeny.com/ipblocks/data/countries/${country}.zone" url="https://www.ipdeny.com/ipblocks/data/countries/${country}.zone"
echo "Baixando lista de IPs para o país: $country" echo "Tentando baixar lista de IPs para o país: $country"
# Baixar o arquivo tmp_file="zone/${country}.zone.tmp"
curl -s -O "$url" target_file="zone/${country}.zone"
# Criar ipset para o país, ignorar se já existir if curl -sSf -o "$tmp_file" "$url"; then
ipset create "$country" hash:net -exist 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."
else
echo "Criando IpSet '$country'."
ipset create "$country" hash:net
fi
# Adicionar cada rede ao ipset # Adicionar cada rede ao ipset
while read -r subnet; do while read -r subnet; do
ipset add "$country" "$subnet" -exist ipset add "$country" "$subnet" -exist
done < "${country}.zone" done < "$target_file"
echo "Concluído para o país $country." echo "Concluído para o país $country."
done done