Skip to content

Instantly share code, notes, and snippets.

@hardware
Created October 7, 2014 09:27
Show Gist options
  • Save hardware/400a22c8b3fff51272f7 to your computer and use it in GitHub Desktop.
Save hardware/400a22c8b3fff51272f7 to your computer and use it in GitHub Desktop.
ipban
CSI="\033["
CEND="${CSI}0m"
CRED="${CSI}1;31m"
CCYAN="${CSI}1;36m"
ipban() {
ACTION=$1
IP=$2
case $ACTION in
"add")
if [[ $IP != "" ]]; then
iptables -A INPUT -s $IP -j DROP
iptables-save > /etc/iptables/rules.v4
fi
;;
"remove")
if [[ $IP != "" ]]; then
iptables -D INPUT -s $IP -j DROP
iptables-save > /etc/iptables/rules.v4
fi
;;
"list")
echo -e "${CCYAN}Liste des adresses ip bannies :${CEND}"
echo -e "${CCYAN}----------------------------------------------------------------${CEND}"
iptables -L INPUT | grep DROP
echo -e "${CCYAN}----------------------------------------------------------------${CEND}"
;;
"count")
CIP=$(iptables -L INPUT | grep DROP | wc -l)
echo -e "Nombre d'adresses ip bannies : ${CRED}$CIP${CEND}"
;;
*)
echo "Utilisation: $0 {add|remove|list|count} [IP]"
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment