Created
March 21, 2013 16:17
-
-
Save thomasv314/5214326 to your computer and use it in GitHub Desktop.
script that adapts mikhailian's implementation of blocking tor nodes... http://mikhailian.livejournal.com/48051.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# script to block tor nodes | |
# original credit for this goes to mikhailian: http://mikhailian.livejournal.com/48051.html | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
if [ "${1}" == "" ]; then | |
echo This script should be run with: ./block-tor ip-address-here | |
exit 0 | |
else | |
echo Blocking all tor exit nodes for: $1 | |
fi | |
echo Created ipset: tor | |
# create a new set for individual IP addresses | |
ipset -N tor iphash | |
echo Downloading tor block list for: $IP | |
# get a list of Tor exit nodes that can access $YOUR_IP, skip the comments and read line by line | |
wget -q https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$1 -O -|sed '/^#/d' |while read IP | |
do | |
# add each IP address to the new set, silencing the warnings for IPs that have already been added | |
echo Blocking: $IP | |
ipset -q -A tor $IP | |
done | |
echo Adding tor ipset to IPTABLES | |
# filter our new set in iptables | |
iptables -A INPUT -m set --match-set tor src -j DROP | |
echo TOR connections should now be blocked. This script will have to be run again on server restart. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script requires ipset be installed on the server.
On ubuntu: sudo apt-get install ipset
http://ipset.netfilter.org/
Usage: