Forum Moderators: phranque

Message Too Old, No Replies

Bandwidth issue - finding a country's ip list. (forgot where)

         

Michel Samuel

6:39 am on Apr 29, 2007 (gmt 0)

10+ Year Member



I have a french website and united states traffic is pretty much useless. And it isn't just a handful of surfers. The united states is clicking in at apx. 200 mb compared to France at 35 mb.

When I make the compare how much it costs me....

To make the long story short, I want to block the United States.

Thats is the .htaccess file below I use......
________________________

#RemoveHandler .html .htm

AddHandler application/x-httpd-php .php .html .htm

_______________________
This is the code I use on my pages......
I use of have it bookmarked in my favourites bookmarks. I've lost it. I am just looking for the input again but for the united states this time.
______________________

<?php
function iptonumber($ip){
$ip=explode('.', $ip);
return $ip[0]*pow(256, 3)+$ip[1]*pow(256, 2)+$ip[2]*256+$ip[3];
}
$ips=unserialize('a:8366:{i:0;a:2:{s:5:"minip";s:8:"33996344";s:5:"maxip";s:8:"33996351";}i:1;a:2:{s:5:"minip";s:9:"152305664";s:5:..... And the list goes on for a long time...............
:"maxip";s:10:"3577603055";}}');
foreach($ips as $ip){
if (($number <= $ip['maxip']) and ($number >= $ip['minip'])){
echo "Sever errored\n";
exit;
}
}
?>

-----------------

jdMorgan

3:26 pm on Apr 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A search on "geoIP" will probably turn up what you are looking for.

A comment on this code, though:
The list of US IP addresses will be huge; I believe China is about to overtake the US, but either way, the list is very big. And as you know, IP address blocks are de-allocated and re-allocated fairly frequently.

Therefore, instead of including the data in-line in a series of "if greater than X and if less than Y" statements, it would be far more efficient to have the script call another program that loads the geoIP list into an array if it is not already loaded, and then returns a pointer to the array whenever it is called. This loader/array-pointer program should then continue to run, listening for further requests from additional instances of the calling script. The calling script could then take the array pointer and index through the array doing the greater-than/less-than compares in a "while" construct, until it finds a matching range or reaches the end of the array.

The advantage here is that IP addresses are in a table, loaded into an array in memory, rather than hard-coded into your script. This way, when the geoIP data changes once a week, you do not need to re-write your code. All you need to do is to restart the geoIP array loader script to re-load the array from your newly uploaded geoIP file. (These files are available in easy-to-use .csv format: plain text, comma-delimited list.)

Now that I've described this in general, I'll have to refer you to the PERL scripting forum for help implementing this, as it is based on general "efficient-computer-programming" knowledge, and I have never coded this application in PERL myself. :)

Also, you might look into a more user-friendly error message: For human-readable "page" requests, such as those for html or php pages, output a message that tells the visitor that your site is specific to France. Otherwise, they will assume that something is wrong with the site, or with their browser or ISP, etc., and may keep trying to access the site. This defeats your purpose. You might even consider providing a redirect or a link and a meta-refresh to a similar US-focused site... You might even find a site willing to reward you for the traffic your refer... ;)

[added] Actually, the always-running PERL script could accept an IP address from the calling script, and then just return an "allowed" or "not allowed" answer to the calling script. That's even simpler. [/added]

Jim

[edited by: jdMorgan at 3:43 pm (utc) on April 29, 2007]

Michel Samuel

3:45 pm on Apr 29, 2007 (gmt 0)

10+ Year Member



Thank you for you help.
But I think my head exploded doing the read of your message.

Why is it never facile?

wilderness

4:51 pm on Apr 29, 2007 (gmt 0)

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



Jim has very thoughtfully advised you of an efficient way to implement a solution.

Some 3-5 years ago and before any types of sorted lists were available, I implemented and a separation of Oceanic ranges from the APNIC ranges, in order to allow access for Oceanic visitors.
The solution remains in effect today, thanks to Jim.

One beginning may be in referrals?
Perhaps you could implement referrals that only come from websites that offer the ".fr" at beginning or end of the domain name.

There are multiple tools with accumulated lists of IP ranges.
One tool is:
http ://www.irnis.net/soft/xipl/
or
http ://www.sharewareconnection.com/titles/ip-country.htm

A google search will eventually lead you to a source:
[google.com...]

Michel Samuel

9:16 pm on Apr 29, 2007 (gmt 0)

10+ Year Member



I am grateful please do not think that I have not.
It is just always so confusing for me.

you learn something and then there are 10 somethings more to learn.

Michel Samuel

9:09 am on May 2, 2007 (gmt 0)

10+ Year Member



I am going to have to get someone to make this for me.
It is at this time of moment much beyond above my abilities.

I need a facility generic i can use with plus of one site.

[edited by: jdMorgan at 12:54 pm (utc) on May 2, 2007]
[edit reason] TOS #20 [/edit]