-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from rulanugrh/main
feat: menambahkan contoh project banned ip dengan csf
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |