1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to block Whole Country from Accessing my website

Discussion in 'Site & Server Administration' started by FreeFun4Every1, Apr 23, 2013.

  1. #1
    FreeFun4Every1, Apr 23, 2013 IP
    SEMrush
  2. Blogmaster

    Blogmaster Blood Type Dating Affiliate Manager

    Messages:
    25,901
    Likes Received:
    1,350
    Best Answers:
    0
    Trophy Points:
    380
    #2
    I am not quite sure how to do it, but I have asked a similar question before about China.

    Here is the answer that I received:


    If you look at his post: http://www.netbuilders.org/building/how-do-i-reconnect-database-30707-2.html
    then maybe you can do the same with Germany?
     
    Blogmaster, Apr 23, 2013 IP
  3. superrichguy

    superrichguy Well-Known Member

    Messages:
    2,148
    Likes Received:
    64
    Best Answers:
    0
    Trophy Points:
    195
    #3
    If you are using cpanel just go to Security-IP Deny Manager and there is a vid that shows you how to do it. It's super easy...
     
    superrichguy, Apr 23, 2013 IP
    Blogmaster likes this.
  4. FreeFun4Every1

    FreeFun4Every1 Prominent Member

    Messages:
    1,110
    Likes Received:
    232
    Best Answers:
    9
    Trophy Points:
    365
    #4
    FreeFun4Every1, Apr 23, 2013 IP
  5. superrichguy

    superrichguy Well-Known Member

    Messages:
    2,148
    Likes Received:
    64
    Best Answers:
    0
    Trophy Points:
    195
    #5
    Sorry I didn't see that. Ok well you could try this.

    Go here http://www.phptutorial.info/iptocountry/the_script.html and download the complete country database (on the top right of page) After its downloaded extract it to your website. It will automatically create a folder called "ip_files"

    Now put this code at the top of your page's:

    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="unknown";
      }
     
      return $country;
    }
    PHP:
    And at the bottom of the pages add this:

    if ($two_letter_country_code=="[COLOR=#0000ff]US[/COLOR]")
      die();
    
    PHP:

    Make sure to back up your site before doing any of this.
    Hope it helps, it worked in a pinch when I was attacked.
     
    superrichguy, Apr 23, 2013 IP
  6. humtuma

    humtuma Notable Member

    Messages:
    1,222
    Likes Received:
    24
    Best Answers:
    3
    Trophy Points:
    200
    #6
    Block via .htaccess
    [​IMG]
     
    humtuma, Apr 23, 2013 IP
  7. trigshady

    trigshady Member

    Messages:
    73
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    48
    #7
    You may block access to your website from specific IP addresses using .htaccess file.
    You need to create this file in your public_html folder and add these example lines:

    order allow,deny
    deny from 127.0.0.1
    allow from all

    These lines will block access for all users using 127.0.0.1 IP address.

    You can download list of each country IPs from countryipblocks website.
     
    trigshady, Apr 28, 2013 IP
  8. jkujami

    jkujami Member

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    you can also use

    www.myipblocker.com

    Select the countries you want to block and copy the script to your site. Easy and works like a charm,,,
     
    jkujami, Sep 12, 2013 IP
  9. Spoiltdiva

    Spoiltdiva Prominent Member

    Messages:
    6,616
    Likes Received:
    1,984
    Best Answers:
    51
    Trophy Points:
    395
    #9
    You should get a *Invalid Clicks Contact Form*. This allows you to disclose what you believe is going on with your account.
     
    Spoiltdiva, Sep 12, 2013 IP
  10. FreeFun4Every1

    FreeFun4Every1 Prominent Member

    Messages:
    1,110
    Likes Received:
    232
    Best Answers:
    9
    Trophy Points:
    365
    #10
    Thanks Diva for ur suggestion but till now on based of other user experience who ever filled that form their account got banned :p
    btw I had already blocked whole country now and no more click bombs on my site.. but after 1 month of removing ad when I had put them again my revenue goes down (it's less than half) :(
     
    FreeFun4Every1, Sep 12, 2013 IP
  11. Corestratagems

    Corestratagems Active Member

    Messages:
    122
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    63
    #11
    You can query this site (http://www.ip2location.com/free/visitor-blocker) by country code and get htaccess format or iptables format. I have a script where you put the country codes in to block and it grabs the IP's for those countries and adds rules using iptables. Better to block unwanted countries from accessing the server and not just the web service when you can. If you want a copy of the script pm me. (It's a modified version of the script found here: http://www.cyberciti.biz/faq/block-entier-country-using-iptables/)
     
    Corestratagems, Oct 21, 2013 IP
  12. jkujami

    jkujami Member

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #12
    Hi there,
    I started a small project a couple of months ago. I purchased ip2location database and made a small website to block countries and ip's. It does not have the best layout but It does what it promises. I use it to block countries accessing my proxy sites and so far I have filtered more than half million accesses.

    The service generates a script to paste into your pages and it does the rest by itself.

    You can check it out at www.myipblocker.com

    Any suggestion or recommendation will be very much appreciated!
     
    jkujami, Oct 22, 2013 IP
  13. ironcladservers

    ironcladservers Well-Known Member

    Messages:
    389
    Likes Received:
    20
    Best Answers:
    4
    Trophy Points:
    115
    #13
    What level of access do you have to the server? The best way would be to block it at the firewall level. If by any chance you use CSF you can block a country code altogether, use the 2 letter country code "DE" to block Germany.
     
    ironcladservers, Oct 22, 2013 IP
  14. iwf-jacob

    iwf-jacob Well-Known Member

    Messages:
    222
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #14
    Erm.. Really not sure how that will help, that's just local addresses..
     
    iwf-jacob, Oct 22, 2013 IP
  15. infinitnet

    infinitnet Member

    Messages:
    56
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    35
    #15
    You can use "iMacros" Firefox and Chrome plugin to automate such tasks.

    The most easy way would be to block all German IP ranges using IPTables. If you don't know how to do that, you can alternatively just create a file called ".htaccess" in your website's directory and put the following content into it to block Germany: http://pastebin.com/raw.php?i=VrXemv0w
     
    infinitnet, Nov 21, 2013 IP
  16. libertyvps

    libertyvps Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #16
    ConfigServerFirewall (CSF) has the ability to set country based blocks. This is a plugin for cPanel and can also be used on Linux servers. It's very accurate too. If you are using CloudFlare you can also use it to block countries.
     
    libertyvps, Nov 24, 2013 IP
  17. damoncloudflare

    damoncloudflare Greenhorn

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #17
    Just a quick note that our country block would currently only offer a captch with a block (humans could still enter the site passing the challenge page).
     
    damoncloudflare, Dec 2, 2013 IP
  18. fare

    fare Active Member

    Messages:
    89
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    95
    #18
    For now using .htaccess or iptables which allow you to paste 6000+ IP range would be a feasible idea. However, please note that it will causes huge amounts of overhead for the Apache web server due to the large number of .htaccess rules the server need to process. This affects the performance of your website.

    Hopefully a full region block would be implemented by CF which would make blocking easier.
     
    fare, Dec 4, 2013 IP
  19. damoncloudflare

    damoncloudflare Greenhorn

    Messages:
    78
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #19
    Something we're looking at. Similar to putting too many rules in Apache, it could actually potentially cause some performance issues having to check too many different blocks.
     
    damoncloudflare, Dec 4, 2013 IP