Skip to content

Commit 39ef172

Browse files
committed
fail2ban - ban and unban an IP Address
1 parent 0df85cc commit 39ef172

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

x-ui.sh

+30-8
Original file line numberDiff line numberDiff line change
@@ -1358,10 +1358,12 @@ iplimit_main() {
13581358
echo -e "${green}\t2.${plain} Change Ban Duration"
13591359
echo -e "${green}\t3.${plain} Unban Everyone"
13601360
echo -e "${green}\t4.${plain} Ban Logs"
1361-
echo -e "${green}\t5.${plain} Real-Time Logs"
1362-
echo -e "${green}\t6.${plain} Service Status"
1363-
echo -e "${green}\t7.${plain} Service Restart"
1364-
echo -e "${green}\t8.${plain} Uninstall Fail2ban and IP Limit"
1361+
echo -e "${green}\t5.${plain} Unban an IP Address"
1362+
echo -e "${green}\t6.${plain} Ban an IP Address"
1363+
echo -e "${green}\t7.${plain} Real-Time Logs"
1364+
echo -e "${green}\t8.${plain} Service Status"
1365+
echo -e "${green}\t9.${plain} Service Restart"
1366+
echo -e "${green}\t10.${plain} Uninstall Fail2ban and IP Limit"
13651367
echo -e "${green}\t0.${plain} Back to Main Menu"
13661368
read -p "Choose an option: " choice
13671369
case "$choice" in
@@ -1389,7 +1391,7 @@ iplimit_main() {
13891391
3)
13901392
confirm "Proceed with Unbanning everyone from IP Limit jail?" "y"
13911393
if [[ $? == 0 ]]; then
1392-
fail2ban-client set 3x-ipl unban --all
1394+
systemctl restart fail2ban
13931395
truncate -s 0 "${iplimit_banned_log_path}"
13941396
echo -e "${green}All users Unbanned successfully.${plain}"
13951397
iplimit_main
@@ -1403,18 +1405,38 @@ iplimit_main() {
14031405
iplimit_main
14041406
;;
14051407
5)
1406-
tail -f /var/log/fail2ban.log
1408+
read -rp "Enter the IP address you want to ban: " ban_ip
1409+
if [[ $ban_ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
1410+
fail2ban-client set 3x-ipl banip "$ban_ip"
1411+
echo -e "${green}IP Address ${ban_ip} has been banned successfully.${plain}"
1412+
else
1413+
echo -e "${red}Invalid IP address format! Please try again.${plain}"
1414+
fi
14071415
iplimit_main
14081416
;;
14091417
6)
1410-
service fail2ban status
1418+
read -rp "Enter the IP address you want to unban: " unban_ip
1419+
if [[ $unban_ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
1420+
fail2ban-client set 3x-ipl unbanip "$unban_ip"
1421+
echo -e "${green}IP Address ${unban_ip} has been unbanned successfully.${plain}"
1422+
else
1423+
echo -e "${red}Invalid IP address format! Please try again.${plain}"
1424+
fi
14111425
iplimit_main
14121426
;;
14131427
7)
1414-
systemctl restart fail2ban
1428+
tail -f /var/log/fail2ban.log
14151429
iplimit_main
14161430
;;
14171431
8)
1432+
service fail2ban status
1433+
iplimit_main
1434+
;;
1435+
9)
1436+
systemctl restart fail2ban
1437+
iplimit_main
1438+
;;
1439+
10)
14181440
remove_iplimit
14191441
iplimit_main
14201442
;;

0 commit comments

Comments
 (0)