Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

39 lines (35 sloc) 0.715 kb
#!/bin/bash
# By Chen.Zhidong
# http://sillydong.com
# Email:njutczd+gmail.com
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
#Begin
usage(){
echo -e "block ipaddress\nUsage: $0 ipaddress"
exit 0
}
valid_ip(){
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
if [ $# -lt 1 ];then
usage
else
if valid_ip "$1";then
iptables -I INPUT -p tcp -s $ip -j DROP
else
echo "$1 is INVALID ip address"
fi
fi
exit 0
#End
Jump to Line
Something went wrong with that request. Please try again.