From cc7e8882d42bc2813e0a05a58e2bca217f869201 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Sun, 21 Jan 2024 23:01:24 +1100 Subject: [PATCH] Add self-incrementing counter --- ufwReject.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ufwReject.sh b/ufwReject.sh index daf7f75..8dd9e49 100755 --- a/ufwReject.sh +++ b/ufwReject.sh @@ -11,6 +11,9 @@ IP_ADDRESSES_STORE="ips.txt" # Scan the kernel log for IP addresses and store them in a file dmesg | grep 'SRC=' | awk -F'SRC=' '{ print $2 }' | awk '{ print $1 }' | sort | uniq | head -n 5000 > "$IP_ADDRESSES_STORE" +# Initialize a counter for new IPs +new_ips=0 + # Populate the UFW reject rule with the IP addresses collected from the kernel log while IFS= read -r ip do @@ -18,8 +21,11 @@ do if ! ufw status | grep -q "$ip" then ufw reject from $ip + # Increment the counter + ((new_ips++)) fi done < "$IP_ADDRESSES_STORE" echo "Done populating UFW reject rule" +echo "$new_ips IP addresses were added" exit 0