Skip to content

Commit

Permalink
Merge pull request #39 from rulanugrh/main
Browse files Browse the repository at this point in the history
feat: menambahkan contoh project banned ip dengan csf
  • Loading branch information
rulanugrh authored Oct 17, 2024
2 parents 2471425 + 38fb78f commit 23d9e81
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions simple_project/banned-ip-with-csf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
white_list="masukan whitelist ip yang kamu butuhkan"

# Jika OS mu centos bisa diganti ke secure bagian auth.log nya
tail -f /var/log/auth.log | while read line
do
cmd=$(echo "$line" | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}')

if echo "$white_list" | grep -qw "$cmd"; then
echo $cmd "this ip is whitelist address"
else
ip_list=$( curl -s https://ipinfo.io/$cmd/json )
country=$(echo $ip_list | jq -r '.country')
ip=$(echo $ip_list | jq -r '.ip')

if [ $country != "ID" ]; then
file="/etc/csf/csf.deny"
if ! grep -q "$ip" "$file"; then
echo $ip >> $file && csf -r
else
echo $ip "have been banned"
fi
fi
fi
done

0 comments on commit 23d9e81

Please sign in to comment.