Echo Snippet

Kick 'n'Dirty



CSS 8 DNS 1 SQL 1 ajax 1 apache 3 bash 11 convert 3 crontab 2 css 1 error 1 fail2ban 2 gogs 1 grav 1 htaccess 3 html 13 ip 8 iptables 2 js 6 mail 2 nano 2 netatmo 1 php 42 php4 1 php5 2 php7 1 plex 1 powershell 1 regex 1 rss 3 secu 1 shell 25 ssl 2 stylus 3 tls 1 windows 1 youtube 2

.

[BASH] Script BAN iptables V.1

[BASH] Script BAN iptables V.1

#!/bin/bash
# Script name : Ban/Unban IP with Iptables


function help {
    echo "Syntax: $0 -[L][u] target(s)"
    echo " Parameters come first. Target is expressed as an IP address."
    echo " No specified parameter will ban the IP."
    echo " -L to list currently banned IPs."
    echo " -u to unban IP(s)."
    exit 1
}

# If no arguments are passed, call the "help" function.
if [ -z "$1" ]; then
    help
fi

# Define some variables
ACTION="-A"
txtred=$(tput setaf 1)
txtyel=$(tput setaf 3)
txtcya=$(tput setaf 6)
txtrst=$(tput sgr0)

while getopts "huL" OPTION
do
    case $OPTION in
        h)
            help
            ;;
        u)
            ACTION="-D"
            shift $(($OPTIND - 1))
            ;;
        L)
            ACTION="-L"
            shift $(($OPTIND - 1))
            ;;
        \?)
            help
            ;;
    esac
done

if [ $ACTION == "-L" ]; then
    echo $txtcya"List of Banned IPs:"$txtrst
    iptables -L INPUT -v -n | grep DROP
else
    # ban work loop
    for ZTARGET in "$@"
    do
        echo $txtcya"Applying action $txtred$ACTION$txtcya to $txtyel$ZTARGET"$txtrst
        iptables $ACTION INPUT -s $ZTARGET -j DROP
    done
fi

bash iptables shell

<iframe width="100%" height="1190" src="https://snippet.echosystem.fr?embed=563a18e9c39ed" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 03/11/2021

Flux RSS de cette page


Echo Snippet 1.84 par Bronco - Page générée en 0.01 s