Zur Zeit dieses Skript Ich verwende China die IP-Adresse zu blockieren:Bash-Skript, müssen für die Schleife helfen
# Create the ipset list
ipset -N china hash:net
# remove any old list that might exist from previous runs of this script
rm cn.zone
# Pull the latest IP set for China
wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone
# Add each IP address from the downloaded list into the ipset 'china'
for i in $(cat ./cn.zone); do ipset -A china $i; done
# Restore iptables
/sbin/iptables-restore < /etc/iptables/rules.v4
Dies funktioniert gut, aber wie kann ich es mit mehreren Ländern?
habe ich versucht, diese aber es funktioniert nicht:
ipset -N blockall hash:net
rm blockall.zone
for i in $(wget -P . http://www.ipdeny.com/ipblocks/data/countries/{cn,in,iq,af,ir,ae,sg,hk,kw,kg}.zone);
do ipset -A blockall $i; done
/sbin/iptables-restore < /etc/iptables/rules.v4
UPDATE
Basierend auf Agnul Antwort habe ich versucht, dies:
rm blockall.zone
# pull files for each country
wget -P . http://www.ipdeny.com/ipblocks/data/countries/{cn,in,iq,af,ir,ae,sg,hk,kw,kg}.zone
# for each country file
for c in *.zone; do
#for each line in country
while read i; do
ipset -A blockall $i;
done <"$c"
done
Dann chmod
ich mein Skript
chmod +x /etc/block-blockall.sh
Allerdings erstellt es nicht die Datei blockall.zone
oder singuläre Datei *.zone
wie es sollte.
Es funktioniert nicht, weil dieses '{cn, in, iq, af, ir, ae, sg, hk, kw , kg} 'es ist falsch ... Was ist die richtige Methode für Array in bash? Entschuldigung im Voraus für die Einfachheit dieser Frage – NineCattoRules