How to ban IPs from <insert country> from viewing my website?

Discussion in 'OT Technology' started by Adlad, Feb 28, 2007.

  1. Adlad

    Adlad Well-Known Member

    Joined:
    Nov 13, 2006
    Messages:
    5,775
    Likes Received:
    51
    I have a personal website that I made for friends and family based in the United Kingdom. I wish to block access to anyone outside the UK, specifically the US.

    This is in no way for malicious reasons, I simple wish to reduce my bandwidth bills.

    I know there are ways to ban specific IPs from your site, but is there a way to ban an entire country? Seems excessive, I know, but I remember reading about when Bush was running for presidency how they blocked anyone outside the US from viewing his personal page (again for bandwidth reasons), so I know it's possible...

    Any help or information is greatly appreciated.

    Thank you in advance.
     
  2. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    http://xkcd.com/c195.html

    Find your country on this image:

    [​IMG]

    Filter all IPs not listed for your nation. I don't know if the UK has a large contiguous block though, and this will not actually get all those IPs.
     
  3. Adlad

    Adlad Well-Known Member

    Joined:
    Nov 13, 2006
    Messages:
    5,775
    Likes Received:
    51
  4. Adlad

    Adlad Well-Known Member

    Joined:
    Nov 13, 2006
    Messages:
    5,775
    Likes Received:
    51
    I came across the following method through a Google search:

    - Make a .htacess file on your server
    - In the .htaccess file post the following text...

    order allow,deny
    allow from all
    deny from 60.254.128.0/18
    deny from 163.60.0.0/16
    deny from 192.103.43.0/24
    deny from 202.72.96.0/20
    deny from 202.76.240.0/21
    deny from 203.77.184.0/21
    deny from 203.144.48.0/20
    deny from 203.187.128.0/19
    deny from 3.0.0.0/8
    deny from 4.0.0.0/8
    deny from 6.0.0.0/8
    deny from 7.0.0.0/8
    deny from 8.0.0.0/8
    deny from 9.0.0.0/8

    ... And so forth

    Do you think this would work?
     
  5. EvanD

    EvanD Active Member

    Joined:
    Jul 12, 2004
    Messages:
    6,727
    Likes Received:
    2
    Location:
    Ottawa, Canada
    For those addresses yeah...unless they use a proxy.

    I ban the addresses from any asian country...everytime I check my logs and see stupid ssh brute force attacks it's always from China or South Korea.
     
    Last edited: Feb 28, 2007
  6. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    I would go the other route - only allow cetain blocks.
     
  7. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    You could always log all incoming IPs along with timecodes, and write a little program that would determine which (if any) IPs are spamming you and rewrite the .htaccess file to compensate.
     

Share This Page