Changes between Initial Version and Version 1 of IpDrop


Ignore:
Timestamp:
02/08/16 09:06:13 (10 months ago)
Author:
chris
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IpDrop

    v1 v1  
     1Script on PuffinServer to block IP addresses using IP tables: 
     2 
     3{{{ 
     4#!/usr/bin/env bash 
     5 
     6# location of the logchange script 
     7DIR=/usr/local/webarch 
     8LOGCHANGE="$DIR/bin/logchange" 
     9 
     10# check that the script is being run by root 
     11if [[ "$(id -u)" != "0" ]] ; then 
     12  echo "You must run '$0' as root or via sudo"  
     13  exit 1 
     14fi 
     15 
     16# check that the logchange script is installed 
     17if [[ ! -f "${LOGCHANGE}" ]] ; then 
     18  echo "You need to install the '${LOGCHANGE}' script before you can run $0" 
     19  exit 2 
     20fi 
     21 
     22# check for a IP address on standard input 
     23if [[ $1 ]]; then 
     24  IP="$1" 
     25elif [[ ! "$1" ]]; then 
     26  echo "Type IP address you would like dropped and then [ENTER]:" 
     27  read ip 
     28  IP=${ip} 
     29fi 
     30 
     31# drop the ip address 
     32iptables -I INPUT -s $IP -j DROP 
     33# save the changes 
     34bash -c "iptables-save > /etc/network/iptables.save" 
     35# record the changes 
     36logchange "$IP : dropped" 
     37 
     38exit 0 
     39}}}