Simple bash script that blocks users using the TOR Browser from accessing a webserver

Status
Not open for further replies.

Peter South

Active Member
606
2013
359
1,660
If you want to block users of the TOR Browser from accessing your website you can run this script on your webserver which uses iptables to block all of the TOR exit nodes. This can be useful to block spammers, trolls, and basically anyone looking to evade a IP ban on a website.....


Code:
#!/bin/bash
# torBlocker.sh - Check TOR's exit node list and uses iptables to block the IPs from accessing a webserver
# Dependency: curl - To install on Ubuntu: apt-get install libcurl3 -y; 
# Note:
# iptables will not remember these after a server is rebooted so you may want to add a task to cron as such: @reboot /path/to/where/you/place/torBlocker.sh
publicIP=`wget -qO- http://ipecho.net/plain ; echo`;
curl "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip="$publicIP | sed 's/^/\-A\ INPUT\ \-s\ /;s/$/\/32\ \-j\ DROP/;' >> /etc/torExitNodeIPs.txt;
iptables-restore < /etc/torExitNodeIPs.txt;
 
Status
Not open for further replies.
Back
Top