From ede2ed56d607252a248692e9963189a6232191d1 Mon Sep 17 00:00:00 2001
From: Pawel Krawczyk
Date: Thu, 13 Nov 2014 11:28:42 +0000
Subject: [PATCH] less verbose
---
blacklist.sh | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/blacklist.sh b/blacklist.sh
index daaf4dd..2d91a1a 100644
--- a/blacklist.sh
+++ b/blacklist.sh
@@ -26,7 +26,7 @@ if [ -z "$(which curl)" ]; then
fi
# create main blocklists chain
-if ! iptables -L ${blocklist_chain_name}; then iptables -N ${blocklist_chain_name}; fi
+if ! iptables -L | grep -q "Chain ${blocklist_chain_name}"; then iptables -N ${blocklist_chain_name}; fi
# inject references to blocklist in the beginning of input and forward chains
if ! iptables -L INPUT|grep -q ${blocklist_chain_name}; then
@@ -42,14 +42,16 @@ for url in $urls; do
tmp=$(mktemp)
tmp2=$(mktemp)
set_name=$(basename $url)
- curl --compressed -k "$url" >"$tmp"
+ curl -s --compressed -k "$url" >"$tmp"
sort -u <"$tmp" | egrep "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" >"$tmp2"
ipset -! create ${set_name} hash:net
while read line; do
- ipset add ${set_name} "$line"
+ ipset -! add ${set_name} "$line"
done <"$tmp2"
iptables -A ${blocklist_chain_name} -m set --match-set "${set_name}" src,dst -m limit --limit 10/minute -j LOG --log-prefix "BLOCK ${set_name} "
iptables -A ${blocklist_chain_name} -m set --match-set "${set_name}" src,dst -j DROP
echo ${set_name} $(ipset list ${set_name} | wc -l)
+ rm "$tmp" "$tmp2"
done
+