Skip to content
WJunction - Webmaster Forum

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

Status
Not open for further replies.
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.

About the author

P
Active Member · Joined
607
Messages
360
Reactions
63
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom