Discuss Scratch

jvvg
Scratcher
1000+ posts

How to block Tor users from accessing your website

Currently, there is an issue of people trying to use Tor (an advanced proxy software) to bypass bans on websites.

However, I have devised a way to prevent Tor from being used to access your website (I am currently piloting this software on futuresight.org). It is fairly easy - it only involves downloading one file to your server and adding a few lines of code.
First, you need to download the list of Tor exit node IPs. The one I used is located at http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv. If you use a different one, you need to update the code accordingly.

Then, on each Tor-protected page, add the following code:
$ips = explode("\n", file_get_contents('/path/to/tor-ips.csv');
if (in_array($_SERVER['REMOTE_ADDR'], $ips)) {
echo 'Please do not use Tor to access this website.'; die;
}

That is the basic code. On the FutureSight website, I did something a bit more advanced to optimize performance: it saves a cookie on your computer if your IP is not detected to be a Tor exit node, and instead of just killing the page as in the above example, it autobans the user from the website for a few days.

jvvg
Professional full stack web developer who first learned programming in Scratch
Administrator and lead engineer on the Scratch Wiki
bobbybee
Scratcher
1000+ posts

How to block Tor users from accessing your website

I honestly don't like this. The code is fine (just arguably poor performance), but I don't think you should block Tor exit nodes. Some users have legitimate reasons for using them.

“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
nXIII
Scratcher
1000+ posts

How to block Tor users from accessing your website

I agree with bobbybee. Many people use Tor to protect their privacy and their personal freedom; please don't prevent them from doing so.

nXIII · GitHub
jvvg
Scratcher
1000+ posts

How to block Tor users from accessing your website

nXIII wrote:

I agree with bobbybee. Many people use Tor to protect their privacy and their personal freedom; please don't prevent them from doing so.
Oh, the reason I'm implementing it is that spambots often like to use Tor, and that people I know are attempting to post harmful stuff on the forums, and this is to prevent them from getting around IP bans. The people I know that use Tor are only trying to protect their freedom to be harmful.

jvvg
Professional full stack web developer who first learned programming in Scratch
Administrator and lead engineer on the Scratch Wiki
BigBlueBlock
Scratcher
500+ posts

How to block Tor users from accessing your website

bobbybee wrote:

I honestly don't like this. The code is fine (just arguably poor performance), but I don't think you should block Tor exit nodes. Some users have legitimate reasons for using them.
scratchisthebest
Scratcher
1000+ posts

How to block Tor users from accessing your website

$ips = explode("\n", file_get_contents('/path/to/tor-ips.csv');
if (in_array($_SERVER['REMOTE_ADDR'], $ips)) {
	echo 'Please do not use Tor to access this website. If you have a legitimate reason for using Tor, please email xxx (at) fgsdfgsdfgfds.com. '; die;
}

fix'd

I am a Lava Expert
lallaway12
Scratcher
100+ posts

How to block Tor users from accessing your website

roter blocking whould be nicer

Mod edit: Removed excessive blank space. Please don't use more space than is necessary for your post!
@Mod Edit: Sorry it was a bug

Last edited by lallaway12 (Aug. 21, 2013 05:07:14)


See my blog ITS MAD so subscribe comment and enjoy http://lallawayrandom.blogspot.co.uk/ ask me what to put up there
Feed my dragons
jvvg
Scratcher
1000+ posts

How to block Tor users from accessing your website

lallaway12 wrote:

roter blocking whould be nicer

Mod edit: Removed excessive blank space. Please don't use more space than is necessary for your post!
What is roter?

jvvg
Professional full stack web developer who first learned programming in Scratch
Administrator and lead engineer on the Scratch Wiki
chocolatepenguin
Scratcher
1000+ posts

How to block Tor users from accessing your website

jvvg wrote:

lallaway12 wrote:

roter blocking whould be nicer

Mod edit: Removed excessive blank space. Please don't use more space than is necessary for your post!
What is roter?
Router?

lallaway12
Scratcher
100+ posts

How to block Tor users from accessing your website

chocolatepenguin wrote:

jvvg wrote:

lallaway12 wrote:

roter blocking whould be nicer

Mod edit: Removed excessive blank space. Please don't use more space than is necessary for your post!
What is roter?
Router?
Yeah

See my blog ITS MAD so subscribe comment and enjoy http://lallawayrandom.blogspot.co.uk/ ask me what to put up there
Feed my dragons

Powered by DjangoBB

Standard | Mobile