Skip to content

Instantly share code, notes, and snippets.

@MarkZhangTW
Last active May 18, 2020 01:37
Show Gist options
  • Save MarkZhangTW/8fd7bf22f2c8187d96d32997c4b2bf61 to your computer and use it in GitHub Desktop.
Save MarkZhangTW/8fd7bf22f2c8187d96d32997c4b2bf61 to your computer and use it in GitHub Desktop.
#sudo lastb -ai | head -n-2 | awk '{print$NF}' | awk '/[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+/{print}' | sort -t. -k1,1n -k2,2n -k3,3n -k4,4n | uniq --count | awk '$1>9{print$2}' > failed.ip.9
sudo lastb -ai | head -n-2 | awk '{print$NF}' | awk '/[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+/{print}' | sort | uniq --count | awk '$1>9{print$2}' > failed.ip.9
for ip in $(cat failed.ip.9); do
sudo firewall-cmd --permanent --zone=public --add-rich-rule="rule family='ipv4' source address='$ip' reject"
done
sudo firewall-cmd --reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment