#!/bin/bash # Check if the script is run as root if [ "$EUID" -ne 0 ]; then echo "Please run as root" exit 1 fi # Check if an IP address is provided as an argument if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi # IP address to block IP_ADDRESS="$1" # Drop and reject traffic from the specified IP address iptables -A INPUT -s $IP_ADDRESS -j DROP iptables -A FORWARD -s $IP_ADDRESS -j DROP iptables -A INPUT -s $IP_ADDRESS -j REJECT iptables -A FORWARD -s $IP_ADDRESS -j REJECT # Display the blocked IP addresses echo "Blocked IP addresses:" iptables -L INPUT -n -v | grep DROP iptables -L FORWARD -n -v | grep DROP echo "IP address $IP_ADDRESS has been blocked and rejected."