Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- PATH=/bin:/usr/bin:/usr/local/bin:/sbin
- CURDATE=`date +%s`
- CURL=/usr/bin/curl
- ISOLIST=(${*})
- OLDDATE=`expr ${CURDATE} - 86400`
- URL=https://ip.ludost.net/raw/country.db.gz
- # Set modification date if database is around
- if [ -f ./country.db ]; then
- MODDATE=`stat -c %Y ./country.db`
- fi
- # Only root can run this script
- if [[ $EUID -ne 0 ]]; then
- echo "This script must be run as root" 1>&2
- exit 1
- fi
- # Check for curl
- if [ ! -x ${CURL} ]; then
- printf "\n \033[1mcurl not found\033[0m\n \033[1mplease install curl\033[0m\n\n"
- exit 1
- fi
- # If database does not exist, Print usage and download database
- if [ ! -f ./country.db ]; then
- printf "\n \033[1mUsage:\t\t./mine.sh <space delimited ISO codes>\033[0m\n"
- printf " \t\t\033[1m ** country ISO codes are two characters **\033[0m\n"
- printf " \033[1mExample:\t./mine.sh cn [ru] [gb] [eu]\033[0m\n"
- printf "\n ** Database not found."
- printf "\n ** A new copy of country.db downloading...\n\n"
- curl -O $URL && gunzip -f ${URL##*/}
- printf "\n"
- exit 1
- # If database exists, but it is older than one day, Print usage and download fresh database
- elif [ -f ./country.db ] && [ ${MODDATE} -lt ${OLDDATE} ]; then
- printf "\n \033[1mUsage:\t\t./mine.sh <space delimited ISO codes>\033[0m\n"
- printf " \t\t\033[1m ** country ISO codes are two characters **\033[0m\n"
- printf " \033[1mExample:\t./mine.sh cn [ru] [gb] [eu]\033[0m\n"
- printf "\n ** Database is older than one day."
- printf "\n ** A fresh copy of country.db downloading...\n\n"
- curl -O $URL && gunzip -f ${URL##*/}
- printf "\n"
- exit 1
- # If country code input is empty, the database exists, and database is not old, Print usage
- elif [ -z "${ISOLIST}" ] && [ -f ./country.db ] && [ ${MODDATE} -gt ${OLDDATE} ]; then
- printf "\n \033[1mUsage:\t\t./mine.sh <space delimited ISO codes>\033[0m\n"
- printf " \t\t\033[1m ** country ISO codes are two characters **\033[0m\n"
- printf " \033[1mExample:\t./mine.sh cn [ru] [gb] [eu]\033[0m\n\n"
- exit 0
- # If script makes it to here, new-ish database exists and the country code has been entered
- # Git-R-Done
- else
- for i in ${ISOLIST[*]}
- do
- IP+=($(grep -i $i ./country.db | awk '{print $1"-"$2}'))
- done
- # Wait message, rules applied
- printf "\n \033[1mOne moment...\033[0m\n\n"
- for r in ${IP[*]}
- do
- ## Print actions on console
- ##printf "iptables -A INPUT -m iprange --src-range $r -j DROP\n"
- # Uncomment line below to really commit
- iptables -A INPUT -m iprange --src-range $r -j DROP
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment