Skip to content

Instantly share code, notes, and snippets.

@random-robbie
Created November 24, 2016 08:41
Show Gist options
  • Save random-robbie/ef4df3d883e6e36b90a40ba0be804e38 to your computer and use it in GitHub Desktop.
Save random-robbie/ef4df3d883e6e36b90a40ba0be804e38 to your computer and use it in GitHub Desktop.
block tor exit nodes hitting your website
# create a new set for individual IP addresses
ipset -N tor iphash
# 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=$YOUR_IP -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
ipset -q -A tor $IP
done
# filter our new set in iptables
iptables -A INPUT -m set --match-set tor src -j DROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment