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 all ips from a specifc country?

Discussion in 'Site & Server Administration' started by rlynch, Feb 25, 2006.

  1. #1
    there is an annoying visitor from "nigeria" spamming my site

    how can i block all ips that resolve to nigeria?

    thanks
     
    rlynch, Feb 25, 2006 IP
  2. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #2
    if you would
    then later they switch to other proxys allocated to another country

    of course you could with
    .htaccess

    deny from xxx.xxx.xxx.xxx ( for a single IP )
    there is certainly a short form to deny en entire group - may be something like
    deny from xxx.xxx
    if a country owns all IP numbers after the first 2 groups ...

    to know what IP groups are belonging to a particular country, you could use the geoIP db offered by
    http://maxmind.com/geoip/

    or any other similar source
     
    hans, Feb 27, 2006 IP
  3. UptimeAgent

    UptimeAgent Peon

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi.

    You can block some amount of IPs from the specific country. That amount can be quite large (you can use the geoIP services as hans suggested) but you cannot be sure that you have blocked all the IPs because of the different reasons (e.g. proxies, international ISPs).

    You can try to use some kind of the "gateway" script which will check each visitor IP in the geoip database and allow/deny access to the other pages but first you should consider if you are ready to spend your time (and probably some money if you will decide to buy the geoIP DB for example) because of a single issue when there are chances that you could solve that issue simply by blocking the malicious user ISP IP address range.
     
    UptimeAgent, Feb 27, 2006 IP
  4. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #4
    there also is a free geoIP db from maxmind for non commercial use updated once a months

    if youi want to go thru all the trouble included in using such heavy measures
    you may also consider that there might be some real surfers being blocked out of your site by blocking an entire country

    a change in proxy used by abusers would make all your work and investment of resources obsolete however
     
    hans, Feb 27, 2006 IP
  5. rlynch

    rlynch Peon

    Messages:
    248
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    does this work:

    order deny,allow
    deny from 81.199.xx.xxx
    deny from 82.193.xx.xxx
    allow from all

    or should i list them a different way?
     
    rlynch, Mar 8, 2006 IP
  6. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #6
    the precise syntax to deny access from and entire sdubnet seems to be

    deny from 81.199
    deny from 82.199

    >> if you want to block all of above subnets

    that's what i found at all below sources for you

    http://www.programmingtalk.com/archive/index.php/t-326.html
    http://www.yorku.ca/computing/students/webpages/central_web/htaccess.html
    http://www.clockwatchers.com/htaccess_block.html

    blocking an entire subnet of course most likely also wil block "nice" users

    Google with

    htaccess deny from multiple IP

    may give more or other info if above is insufficient
     
    hans, Mar 8, 2006 IP
  7. rlynch

    rlynch Peon

    Messages:
    248
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    cool thanks for the help

    do you know if its:

    deny, allow

    or

    allow, deny

    ive seen it both ways...
     
    rlynch, Mar 8, 2006 IP
  8. hans

    hans Well-Known Member

    Messages:
    2,923
    Likes Received:
    126
    Best Answers:
    1
    Trophy Points:
    173
    #8
    hans, Mar 8, 2006 IP
  9. Maurice Randall

    Maurice Randall Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I developed a method for using iptables running on Linux for blocking out whole countries. It's a php script, so it uses a browser interface and is easy to setup and use. It lets you pick the countries you want to block and then it will create a file filled with iptables rules. You then use a simple command to load this in. From then on, the countries you have chosen will be dropped on the first packet that comes in. No access whatsoever, no pinging, nothing.

    Everyone else gets in OK. It works very fast because only the first packet in a chain is checked and even then the first packet comes in very fast due to the efficiency of the iptables code in the Linux kernel.

    Ever since I implemented this and blocked out all the countries that seem to cause the most problems, my web server and email server has regained considerable bandwidth. The error logs are much smaller now.

    It's a free download. You can check it out at FixingTheWeb.com.

    -Maurice
     
    Maurice Randall, Mar 23, 2006 IP
  10. Maurice Randall

    Maurice Randall Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    For anyone who has already downloaded my country blocking package from FixingTheWeb.com, I have just made a slight upgrade which allows you to use your choice of either the ip-to-country database or the geoip database.

    You don't have to do any special configuration, the new setup program will find whichever database file you have copied to the working directory and use it.

    -Maurice
     
    Maurice Randall, Mar 24, 2006 IP
  11. pshelter

    pshelter Peon

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    pshelter, Apr 10, 2007 IP
  12. wildcard

    wildcard Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Hi,

    A fast and simple solution is to block visitors from Nigeria, or any other country in that matter is to use an .htaccess file to block traffic from this country. The site located at blockacountry.com can help you with this last procedure. Simply select which countries you want to block, in your case only Nigeria, press the okay button and the website creates an .htaccess document for you. Upload this file to your server and your annoying spam visitors should be history.

    Wildcard
     
    wildcard, Jul 7, 2007 IP
  13. mangia

    mangia Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Well what do you think about php script who would read database with problematic IPs and remove some content on your website. For example if visitor came from problematic country, don't show adsense code. :)

    Any ideas?
     
    mangia, Jul 7, 2007 IP
  14. wildcard

    wildcard Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #14
    This can be done also… just create a db with ip addresses or ranges you want to block. Create some php code that checks what ip the visitor has. Verify if the visitor should see the advertisement. That’s all, no rocket science involved here.

    If you need an example code let me know and I shall see what I can do!

    Wildcard
     
    wildcard, Jul 7, 2007 IP
  15. deny

    deny Active Member

    Messages:
    365
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #15
    blockacountry.com have very nice and easy concept to help people for blocking country. However ip ranges list is not complete. If you compare ip ranges list with ip ranges from
    http://www.ipaddresslocation.org/ip_ranges/get_ranges.php
    then is clearly that many ranges are not listed.
    Example:

    
    For Albanie ranges list from blockacountry.com :
    
    <Limit GET HEAD POST>
    order allow,deny
    deny from 77.242.16.0/20
    deny from 80.78.64.0/20
    deny from 80.90.80.0/20
    deny from 80.91.112.0/20
    deny from 84.20.64.0/19
    deny from 194.1.149.0/24
    deny from 213.207.32.0/19
    deny from 217.24.240.0/20
    allow from all
    </LIMIT>
    
    Code (markup):
    
    For Albanie ranges list from IpAddressLocation.org
    62.75.65.0 62.75.66.255
    65.110.38.40 65.110.38.49
    66.111.34.70 66.111.34.79
    66.111.34.120 66.111.34.129
    66.111.45.80 66.111.45.89
    66.111.50.130 66.111.50.139
    66.227.2.137 66.227.2.144
    77.242.16.0 77.242.31.255
    80.78.64.0 80.78.79.255
    80.90.80.0 80.90.95.255
    80.91.112.0 80.91.127.255
    81.31.202.52 81.31.202.55
    84.20.64.0 84.20.95.255
    85.94.124.0 85.94.127.255
    193.220.74.0 193.220.74.31
    193.254.1.0 193.254.3.255
    194.1.149.0 194.1.149.255
    207.241.168.0 207.241.168.255
    207.241.174.0 207.241.174.255
    213.149.101.0 213.149.101.255
    213.149.105.64 213.149.105.79
    213.149.108.0 213.149.110.255
    213.149.113.240 213.149.114.255
    213.207.32.0 213.207.63.255
    213.209.181.0 213.209.181.63
    213.209.187.64 213.209.187.127
    217.24.240.0 217.24.255.255
    
    Code (markup):
     
    deny, Jul 7, 2007 IP
  16. wildcard

    wildcard Peon

    Messages:
    58
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Thanks for the feedback. I will look into it and add the missing ip ranges!

    Wildcard
     
    wildcard, Jul 8, 2007 IP
  17. Kezi

    Kezi Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #17
    Has anyone gone to the link (link had to be removed), kindly suggested above and tried to do it just with the 2 letters as mentioned on the link? I've tried it for a few different countries and it doesn't seem to work ?

    ?
     
    Kezi, Jul 12, 2007 IP
  18. ThreeGuineaWatch

    ThreeGuineaWatch Well-Known Member

    Messages:
    1,489
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    140
    #18
    What happens when the annoying user finds out he is blocked and then starts using a proxy server located in the US to spam your site? ;) You can go on forever chasing fools like that - not sure IP blocking is the best method. :)
     
    ThreeGuineaWatch, Jul 12, 2007 IP
  19. Kezi

    Kezi Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #19
    OK, so what would be the easiest way to block all other countries from viewing the websites apart from people in the UK ?
     
    Kezi, Jul 12, 2007 IP
  20. Kezi

    Kezi Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #20
    Anyone know ?
     
    Kezi, Aug 13, 2007 IP