mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 04:10:59 -05:00
26 lines
657 B
Bash
26 lines
657 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
if [ "$EUID" -ne 0 ]; then
|
||
|
echo "Please run this script as root or sudo"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Store the IP addresses in a file
|
||
|
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"
|
||
|
|
||
|
# Populate the UFW reject rule with the IP addresses collected from the kernel log
|
||
|
while IFS= read -r ip
|
||
|
do
|
||
|
# Check if the IP is already in the UFW rules
|
||
|
if ! ufw status | grep -q "$ip"
|
||
|
then
|
||
|
ufw reject from $ip
|
||
|
fi
|
||
|
done < "$IP_ADDRESSES_STORE"
|
||
|
|
||
|
echo "Done populating UFW reject rule"
|
||
|
exit 0
|