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.

Peter South

Experienced Member
607
2013
360
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
Experienced Member · Joined
607
Messages
360
Reactions
63
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom