Welcome to WebmasterWorld Guest from 54.211.82.105

Forum Moderators: phranque

Message Too Old, No Replies

Blocking Site For A Country

     
7:37 am on May 19, 2012 (gmt 0)

Junior Member from IN 

5+ Year Member

joined:May 19, 2010
posts:86
votes: 0


Hello all,
I need your help on my odd question. Actually one of my friends wants to create a website but that should be blocked for a Country. I mean he wants his site should not be accessed by a particular country users.

Technically is this possible?

I am puzzled ! So I need your help if this is possible.

Thanks
8:51 am on May 19, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10589
votes: 21


you can block IP addresses but not geographies.
depending on which country it can be simple or nearly impossible to define the IP range(s) associated with that country.
if your visitor is determined enough to access the site through a proxy on an unblocked IP address you're out of luck.
9:12 am on May 19, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:July 25, 2006
posts: 460
votes: 0


Technically it is possible, but it's not as easy as one might wish. IP address ranges are not assigned by country, so any large range probably has smaller sub-ranges within it from a variety of different countries. That is, if you see an IP address from your banned country, you can't block all IPs starting with similar digits, because you'll probably be banning visitors from other countries, too.

In your web search for solutions, the keyword you need is "GeoIP" or maybe "geolocation". I believe that will lead you to databases and subscription lookup services that can translate an individual IP to its country of origin.

To implement on your server, you'll need to look up the IP of each incoming request to determine its country of origin. If it is the banned country, return a 403 response.

I believe there might be an Apache module that can carry out these lookups. Or if your code is all PHP, you can probably do it in PHP. However you do it, it probably adds significant overhead to the handling of each request.

An alternative to a subscription lookup service would be to manually build your own database of as many IP address ranges as you can find from the banned country (not an easy project, I suspect), and use your own code to consult that database for each request.
10:00 am on May 19, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10589
votes: 21


if it's an apache server you can use a couple of methods of Access Control:
http://httpd.apache.org/docs/2.2/howto/access.html [httpd.apache.org]
12:47 am on May 20, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13252
votes: 358


IP address ranges are not assigned by country, so any large range probably has smaller sub-ranges within it from a variety of different countries. That is, if you see an IP address from your banned country, you can't block all IPs starting with similar digits, because you'll probably be banning visitors from other countries, too.

And how! Currently about 2/3 of the "Deny from..." section of my htaccess is devoted to The Unwanted Country-- and that's nowhere near a complete list. To keep things sane I cut off at /16 (that is, aa.bb) unless I meet an individual nasty in a smaller range. If I included everything, the list would be more than twice as long.

You could throw in a language block. But unless you're locking out a major European country-- somehow I doubt this is what you want to do-- the language probably won't even show up in the UA.
6:14 am on May 20, 2012 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:May 27, 2005
posts:428
votes: 3


Blocking by language detected in the user-agent may be of use here.
11:33 am on May 23, 2012 (gmt 0)

Junior Member from IN 

5+ Year Member

joined:May 19, 2010
posts:86
votes: 0


Thanks you all for taking time answer my query.

I have used Block by IP method :)

Thanks again.
5:16 pm on June 14, 2012 (gmt 0)

New User

joined:June 14, 2012
posts:4
votes: 0


on robots file?
8:50 pm on June 14, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10589
votes: 21


the only thing you can block in robots.txt is crawling by well-behaved bots.
9:29 pm on June 14, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Aug 30, 2002
posts: 2529
votes: 47


If you are on a dedicated Linux server then it may be possible to block at the IP level using iptables or similar firewall software. This essentially prevents any traffic from the problem IPs ever getting to Apache. However with some countries you may be blocking thousands of IP ranges and you are not going to get a 100% solution due to the web proxy issue.

Regards...jmcc