Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Other Search Engines


You are currently viewing our The Other Search Engines as a guest. Please register to participate.
Login



Reply
Can an entire country be blocked in .htaccess?
Old 12-24-2006, 05:43 AM Can an entire country be blocked in .htaccess?
Banned

Posts: 253
Name: Michel Samuel
Trades: 0
Forgive me if I sound kind of stupid.
(That's because I am)

I was thinking about that and I thought it might be possible if I knew the entire grouping of IPs that country uses.

But the list would be HUGE.

So I figure there must be some way to do it with GEO-IP but could that be done in the .htaccess file?
Michel Samuel is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-24-2006, 06:56 AM Re: Can an entire country be blocked in .htaccess?
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
If the country's IP-adresses are in afixed range (which they probably are), you could just do something like this:

Code:
order allow,deny
deny from 24.2
allow from all
(blocks every IP that begins with 24.2).

If not, you should try to dynamicly create your .htaccess file. Make a script that reads out the Geo-IP database and let it acluculate all IP adresses you have to block. Then make it write the .htaccess file.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Old 12-24-2006, 09:37 AM Re: Can an entire country be blocked in .htaccess?
Banned

Posts: 253
Name: Michel Samuel
Trades: 0
Quote:
Originally Posted by Orodreth View Post
If the country's IP-adresses are in afixed range (which they probably are), you could just do something like this:

Code:
order allow,deny
deny from 24.2
allow from all
(blocks every IP that begins with 24.2).
Sounds simple enough.
The hard part will be finding out a country's IP range.

Quote:
Originally Posted by Orodreth View Post
If not, you should try to dynamicly create your .htaccess file. Make a script that reads out the Geo-IP database and let it acluculate all IP adresses you have to block. Then make it write the .htaccess file.
Waaay over my abilities.

I found this...

Code:
 
<?php
 
if ($_SERVER <'HTTP_X_FORWARDED_FOR' >) 
$ip = $_SERVER <'HTTP_X_FORWARDED_FOR' >;
else 
$ip = $_SERVER <'REMOTE_ADDR' >;
 
$two_letter_country_code=iptocountry($ip);
 
function iptocountry($ip) { 
$numbers = preg_split( "/\./", $ip); 
include("ip_files/".$numbers <0 >.".php");
$code=($numbers <0 > * 16777216) + ($numbers <1 > * 65536) + ($numbers <2 > * 256) + ($numbers <3 >); 
foreach($ranges as $key => $value){
if($key<=$code){
if($ranges <$key > <0 >>=$code){$country=$ranges <$key > <1 >;break;}
}
}
if ($country==""){$country="unkown";}
return $country;
}
if ($two_letter_country_code=="US")
die();
?>
It's supposed to be loaded at the top of a page.
But I can't figure out where exactly that is... ((Sorry I'm really a hack and an idiot))
Also you supposed to download the IP range from this site. http://www.phptutorial.info/iptocountry/the_script.html
and install it on your domain.

Last edited by Michel Samuel; 12-24-2006 at 09:39 AM..
Michel Samuel is offline
Reply With Quote
View Public Profile
 
Old 12-25-2006, 07:44 PM Re: Can an entire country be blocked in .htaccess?
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
The top of your page is the absolute top. Really the beginning of a page (before <html> of <!Doctype>)

For the script. I'll give you the needed .htaccess file if you want. I'll generate it tomorrow.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Old 12-26-2006, 05:50 AM Re: Can an entire country be blocked in .htaccess?
Banned

Posts: 253
Name: Michel Samuel
Trades: 0
Quote:
Originally Posted by Orodreth View Post
The top of your page is the absolute top. Really the beginning of a page (before <html> of <!Doctype>)

For the script. I'll give you the needed .htaccess file if you want. I'll generate it tomorrow.
Are you sure your name isn't santa clause?
THANKS!
Michel Samuel is offline
Reply With Quote
View Public Profile
 
Old 12-26-2006, 09:19 PM Re: Can an entire country be blocked in .htaccess?
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Hehe, no, my name is not Santa Claus, but that doesn't mean I can't help you. It's only a few minutes job.

Anyways, I forgot to ask: which country do you want to block?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Old 12-27-2006, 07:30 AM Re: Can an entire country be blocked in .htaccess?
Banned

Posts: 253
Name: Michel Samuel
Trades: 0
Quote:
Originally Posted by Orodreth View Post
Hehe, no, my name is not Santa Claus, but that doesn't mean I can't help you. It's only a few minutes job.

Anyways, I forgot to ask: which country do you want to block?
A total lock down on england is needed.

or a complete permit france only will do.
Michel Samuel is offline
Reply With Quote
View Public Profile
 
Old 12-27-2006, 08:08 PM Re: Can an entire country be blocked in .htaccess?
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Ok, using .htaccess ssems impossible for a country: the needed file is more than 554 MB!

I wrote you a php script instead. Put its content at the top of every page you want to block: http://thomas.weyn.be/blockUK.txt
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Old 12-28-2006, 11:44 AM Re: Can an entire country be blocked in .htaccess?
Banned

Posts: 253
Name: Michel Samuel
Trades: 0
Thank you soooo much!!
Can I pick your brain for a moment so I can learn something. (Get to know me and yes.. I'm an idiot.)

It looks beautifully simple.
how does it know the IP range?
Where did you find that out?
Is there a master list of a nation's IPs?
Also when working with PHP can I put the script in an html file? or does it have to be a PHP file?

Last edited by Michel Samuel; 12-28-2006 at 11:47 AM..
Michel Samuel is offline
Reply With Quote
View Public Profile
 
Old 12-28-2006, 01:22 PM Re: Can an entire country be blocked in .htaccess?
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
No thanks, and sorry, but you can't pick my brain. You can always ask me questions, however, I'll be glad to help.

Normally, you have to put the script in a php file, but after making a few changes in .htaccess, you can also use it in html files. Just add this to your .htaccess:

Code:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
My script get's the IP-range from the very long encoded string you see. When decoded, it's an array containing all IP-ranges for the UK.

You can get the "master list of a nation's IPs" here: http://ip-to-country.webhosting.info/node/view/6
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Old 12-30-2006, 05:11 AM Re: Can an entire country be blocked in .htaccess?
Banned

Posts: 253
Name: Michel Samuel
Trades: 0
Quote:
Originally Posted by Orodreth View Post
No thanks, and sorry, but you can't pick my brain. You can always ask me questions, however, I'll be glad to help.

Normally, you have to put the script in a php file, but after making a few changes in .htaccess, you can also use it in html files. Just add this to your .htaccess:

Code:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
My script get's the IP-range from the very long encoded string you see. When decoded, it's an array containing all IP-ranges for the UK.

You can get the "master list of a nation's IPs" here: http://ip-to-country.webhosting.info/node/view/6
First let me with you a good new year and all the best.

Next...
I get it!!! I actually get something!! (Wow not an easy thing with me)
Since the .htaccess file is read first it instructs the browser to ignore the .html extensions and treat them as httpd-php, etc.

totally cool.

Ok do you know of a UK proxy some place so I can test this out?
Michel Samuel is offline
Reply With Quote
View Public Profile
 
Old 01-06-2007, 05:10 PM Re: Can an entire country be blocked in .htaccess?
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Happy New Year. I'm late, I know, but I was on holidays, without internet.

Anyways, I'm afraid I don't know any UK proxy. Sorry about that.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
Reply With Quote
View Public Profile Visit Orodreth's homepage!
 
Reply     « Reply to Can an entire country be blocked in .htaccess?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61431 seconds with 12 queries