-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.sh
68 lines (56 loc) · 1.9 KB
/
project.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
clear
figlet -c Bad Ip
figlet -f ~/.local/share/fonts/3d.flf "Hello World"
sudo rm ip.txt;
grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' projet.log > ip.txt
sudo rm BadIp.txt;
input="ip.txt"
while IFS= read -r line
do
echo ""
info=$(curl -Gs https://api.abuseipdb.com/api/v2/check \
--data-urlencode "ipAddress=$line" \
-d maxAgeInDays=90 \
-H "Key: $(cat key.txt)" \
-H "Accept: application/json" | jq .)
COUNTRY=$(echo $info | jq -r '.data.countryCode')
DOMAIN=$(echo $info | jq -r '.data.domain')
ABUSE_SCORE=$(echo $info | jq -r '.data.abuseConfidenceScore')
LAST_UPDATE=$(echo $info | jq -r '.data.lastReportedAt')
if [ "$ABUSE_SCORE" -gt 25 ]
then
echo -e "\e[96mIP Lookup Details:"
echo "------------------"
echo -e "\e[39mBad Ip: \e[91m$line";
echo -e "\e[39mABUSE_SCORE: \e[91m$ABUSE_SCORE"%"";
echo -e "\e[39mCOUNTRY: $COUNTRY";
echo -e "\e[39mDOMAIN: $DOMAIN";
echo -e "\e[39mLAST_UPDATE: $LAST_UPDATE";
echo $line >> BadIp.txt;
else
echo -e "\e[96mIP Lookup Details:"
echo "------------------"
echo -e "\e[39mGood Ip: \e[92m$line";
echo -e "\e[39mABUSE_SCORE: \e[32m$ABUSE_SCORE"%"";
echo -e "\e[39mCOUNTRY: $COUNTRY";
echo -e "\e[39mDOMAIN: $DOMAIN";
echo -e "\e[39mLAST_UPDATE: $LAST_UPDATE";
fi
done < "$input"
clear
input="BadIp.txt"
while IFS= read -r line
do
sudo iptables -A INPUT -s $line -j DROP;
echo -e "\e[39mIp Blocked: \e[91m$line";
done < "$input"
#send email
echo -e "\e[39mDo you want to send a report to your mail ? [(Y)es/(N)o]"
read rep
if [ $rep = "" ] || [ $rep = "Y" ] || [ $rep = "y" ]
then
echo "Enter your mail address: "
read mail
cat BadIp.txt | sendmail $mail -F "Rapport";
fi