Forum Moderators: phranque
Any ideas would be appreciated from someone who has been down this road.
The best way to do it is the way with which you are most comfortable. This is important, because if you make an error and block real customers, it can be a big disaster. So, whatever method seems clearest and easiest for you is the "right way" to do it. Efficiency is a concern, but a relatively small one; Your server works for you, and not the other way around... :)
Another tip: Always make your custom 403 error page polite!
Jim
In this case the server is the web server of a financial services company that only does business in the US. I don't really want to block the UK or Canada or any other country that conceivably someone could have a dual residency etc. or that I can get similiar industry links with for example... But, I can reasonably feel safe blocking most parts of China, Korea and Eastern Europe and part of lacnic I think. Is there a shortcut to download a list posted somewhere along these lines?
I am thinking to blanket block some addresses in hosts.deny and then add a spider trap to get the others that come up... realizing I will probably have to hand edit the .htaccess frequently to free up dynamic domestic addresses. <added> I would think the ipchains route would be better on a separate server, but the server is currently colocated. </added>
[edited by: idoc at 7:12 pm (utc) on Mar. 31, 2004]
I also use a SQL database method for sites hosted in places where I don't have access to configure the network hardware myself. I have a database of IP ranges (stored in DEC format for speed/range capabilities).
Using an include on every page, I get the visitor's IP address and convert it to DEC with a simple function. Then I execute the following code:
If cdbl(con.execute("proc_VerifyIP <theIPaddress>")(0)) > 0 Then response.redirect "/accessdenied.htm" End If
(I'm using ASP code but you could of course modify this for the language of your choice).
Basically a stored procedure takes the decimal IP address and queries a table of "bad" IP ranges. The SQL code is something like SELECT count(*) FROM IPRanges WHERE VisitorIP >= @IPAddress AND VisitorIP <= @IPAddress
If the IP address of the visitor falls within that range, the stored procedure will return a count of 1 or greater. If nothing exists, count will be zero. The script on the website says if it returns anything OTHER THAN zero, redirect them to an access denied page.
The site I have running this receives nearly 100k hits a day and there is no loss of performance. I also have a ton of other things that go on with the database, this is just part of it. So if you're worried about DB performance doing it this way, DON'T.
# ip blocks
ALL: 62.248.
ALL: 80.96.75.
ALL: 81.6.
ALL: 81.7.
ALL: 142.179.
ALL: 164.77.74.
ALL: 196.30.116.
ALL: 200.
ALL: 210.
ALL: 211.
ALL: 217.131.
ALL: 218.
ALL: 219.92.
Did I miss any really egregious ip blocks? And also I put up the birdman's spider trap. It will be interesting. ;)
[okean.com...]
At what point in size does a bloated hosts.deny or a .htaccess file slow up a request I wonder?
<added> after looking over several months of server logs for certain apnic class A addresses... I could not find even one legitimate surfer for some of them so I will be using a broader brush than most folks can I think. </added>