GeoIP blocking of countries
05-18-2007, 02:14 PM
|
GeoIP blocking of countries
|
Posts: 253
Name: Michel Samuel
|
I have a quasi GeoIP block set up on my sites.
The problem is it only blocks the front page. (Ie. the index file.)
Well long story short my sites are structured to the francophone community.
But american traffic is almost 5 to 1 and it's growing.
sounds great but I can NOT use the american traffic.
I need a lock down system of blocking the United States.
My host provides an IP block system independant of the .htaccess file.
Is there any place I can get a list of the american ips. (Yes I know it will be huge)
Last edited by Michel Samuel : 05-18-2007 at 02:17 PM.
|
|
|
|
05-18-2007, 03:16 PM
|
Re: GeoIP blocking of countries
|
Posts: 3,191
|
It would probably be easier to fix your current setup than to try and find a list of all US IP's. Can I see the code your using to block traffic?
|
|
|
|
05-19-2007, 06:58 AM
|
Re: GeoIP blocking of countries
|
Posts: 442
Name: Damien
|
Quote:
Originally Posted by Michel Samuel
Is there any place I can get a list of the american ips. (Yes I know it will be huge)
|
MaxMind GeoLite Country may do?
Other than that, how are you currently blocking - .htaccess is probably one of the better methods?
__________________
Layershift :: DDS & Dedicated, UK & USA-based Managed Virtuozzo VPS, Reseller & Shared Hosting
Experienced Parallels Platinum Partners (Plesk since 2001, Virtuozzo since 2004)
|
|
|
|
05-19-2007, 02:07 PM
|
Re: GeoIP blocking of countries
|
Posts: 253
Name: Michel Samuel
|
Quote:
Originally Posted by Republikin
It would probably be easier to fix your current setup than to try and find a list of all US IP's. Can I see the code your using to block traffic?
|
The list of ips and database comes from the maxmind site
This is the code that is being used.
Problem is only the first page is really being protected.
I'm really only targeting a specific area. The non-desireable traffic is far out stripping the desireable traffic. (almost 5 to 1)
Quote:
<?php
$host='localhost'; //Enter your host here within the quotes
$username='geoip'; //Enter your username of the mysql database
$passwd='password'; //Enter the password for that username
$database='geoip'; //This is where you database info is stored.
$nexturl='http://mysitel.com/index1.html'; // This is where you will be redirected if it is a desireable IP
$db = mysql_connect($host,$username,$passwd) or die ("mysql_connect() failed: " . mysql_error());
mysql_select_db($database,$db) or die ("mysql_select_db() failed: " . mysql_error());
$remote = $_SERVER['REMOTE_ADDR'];
$cc=getCCfromIP($remote,$db);
//$cc=getCOUNTRYfromIP($remote,$db);
if ( $cc=='CA' || $cc=='CH'|| $cc=='BE' || $cc=='MC' || $cc=='LU' || $cc=='FR' )
header("Location: $nexturl");
else
echo "The resouce is no longer available or has been removed. Please remove reference to this site."; // message the bad people to go away from here.....
function getALLfromIP($addr,$db) {
// this sprintf() wrapper is needed, because the PHP long is signed by default
$ipnum = sprintf("%u", ip2long($addr));
$query = "SELECT cc, cn FROM ip NATURAL JOIN cc WHERE ${ipnum} BETWEEN start AND end";
$result = mysql_query($query, $db);
if((! $result) or mysql_numrows($result) < 1) {
//exit("mysql_query returned nothing: ".(mysql_error()?mysql_error():$query));
return false;
}
return mysql_fetch_array($result);
}
function getCCfromIP($addr,$db) {
$data = getALLfromIP($addr,$db);
if($data) return $data['cc'];
return false;
}
function getCOUNTRYfromIP($addr,$db) {
$data = getALLfromIP($addr,$db);
if($data) return $data['cn'];
return false;
}
function getCCfromNAME($name,$db) {
$addr = gethostbyname($name);
return getCCfromIP($addr,$db);
}
function getCOUNTRYfromNAME($name,$db) {
$addr = gethostbyname($name);
return getCOUNTRYfromIP($addr,$db);
}
?>
|
|
|
|
|
05-19-2007, 02:10 PM
|
Re: GeoIP blocking of countries
|
Posts: 253
Name: Michel Samuel
|
Quote:
Originally Posted by damien_ls
MaxMind GeoLite Country may do?
Other than that, how are you currently blocking - .htaccess is probably one of the better methods?
|
I'm a photographer and not a coder.
But I'm blocking out entire nations. So the list would be HUGE in the .htaccess file.
I really only want part of Canada, Belgium, Swiss, Luxembourg and France.
So one of the things I thought would work was a set up that instead of denied IPS... but gave permission to certain IP.
|
|
|
|
05-19-2007, 02:16 PM
|
Re: GeoIP blocking of countries
|
Posts: 442
Name: Damien
|
Ok. Surely all you need to do is put that code at the top of every page on your site (e.g. php require) and change it very slightly so that it ONLY redirects (or shows the message etc.) if they're blocked, otherwise continues to display the page?
__________________
Layershift :: DDS & Dedicated, UK & USA-based Managed Virtuozzo VPS, Reseller & Shared Hosting
Experienced Parallels Platinum Partners (Plesk since 2001, Virtuozzo since 2004)
|
|
|
|
05-19-2007, 02:33 PM
|
Re: GeoIP blocking of countries
|
Posts: 3,191
|
Wow, that is some sloppy code and could use some cleaning up and commenting. Anyways, damien_ls is on the right track. Just put that code into a seperate file and include that file at the top of every page you need to protect.
|
|
|
|
05-19-2007, 03:12 PM
|
Re: GeoIP blocking of countries
|
Posts: 253
Name: Michel Samuel
|
Unfortunately the coding is sloppy because I stink as a programer.
That code was pieced together from several sources. (Not smart enough to write it from scratch)
Tolerate me for a moment...
I'm reading over the php require link.
So I should be able to place the php require at at the top of my pages.
Then have them call up that script. OK! got that part.
But how do I change that script ?
|
|
|
|
05-19-2007, 04:44 PM
|
Re: GeoIP blocking of countries
|
Posts: 3,191
|
You said that works right so it shouldn't need any changes in order to get you up and running immediately however, if you want to make it more efficient and streamlined there are a few things that can be done. So what is it exactly that you want to change about it?
|
|
|
|
05-19-2007, 05:27 PM
|
Re: GeoIP blocking of countries
|
Posts: 442
Name: Damien
|
Quote:
Originally Posted by Michel Samuel
But how do I change that script ?
|
Quote:
Originally Posted by Republikin
You said that works right so it shouldn't need any changes in order to get you up and running immediately however, if you want to make it more efficient and streamlined there are a few things that can be done. So what is it exactly that you want to change about it?
|
I believe that this code will need to be changed if he's including it at the top of every page...
PHP Code:
if ( $cc=='CA' || $cc=='CH'|| $cc=='BE' || $cc=='MC' || $cc=='LU' || $cc=='FR' )
header("Location: $nexturl");
else
echo "The resouce is no longer available or has been removed. Please remove reference to this site."; // message the bad people to go away from here.....
My suggestion would be:
PHP Code:
if (!( $cc=='CA' || $cc=='CH'|| $cc=='BE' || $cc=='MC' || $cc=='LU' || $cc=='FR' )) {
echo "The resouce is no longer available or has been removed. Please remove reference to this site."; // message the bad people to go away from here.....
exit(); // very important to stop execution at this point or otherwise page will still be shown etc.
}
__________________
Layershift :: DDS & Dedicated, UK & USA-based Managed Virtuozzo VPS, Reseller & Shared Hosting
Experienced Parallels Platinum Partners (Plesk since 2001, Virtuozzo since 2004)
|
|
|
|
05-20-2007, 02:58 AM
|
Re: GeoIP blocking of countries
|
Posts: 253
Name: Michel Samuel
|
OK....
End the execution of the.
Now do I have to each page call that script? (in oder to prevent deep linking?)
Because as it stands the script is named index.php.
When an undesireable country ip tries to log in it tells them to go away.
But a desireable one gets seamlessly redicted to my priemer page.
|
|
|
|
05-20-2007, 10:51 AM
|
Re: GeoIP blocking of countries
|
Posts: 442
Name: Damien
|
Take all of the code from index.php and rename it something more appropriate - perhaps includes/country_checker.php or something like that...
Then at the top of all pages in your site, you'll need to put the following:
PHP Code:
<?php require('includes/country_checker.php'); ?>
Finally, because you were redirecting from index.php to whatever your actual home page is called, you'll want to create a 301 redirect from index.php to your actual home page; you could do this via PHP or via .htaccess.
See this tutorial for 301 redirect via various methods.
__________________
Layershift :: DDS & Dedicated, UK & USA-based Managed Virtuozzo VPS, Reseller & Shared Hosting
Experienced Parallels Platinum Partners (Plesk since 2001, Virtuozzo since 2004)
|
|
|
|
05-21-2007, 10:29 AM
|
Re: GeoIP blocking of countries
|
Posts: 253
Name: Michel Samuel
|
Quote:
Originally Posted by damien_ls
Take all of the code from index.php and rename it something more appropriate - perhaps includes/country_checker.php or something like that...
Then at the top of all pages in your site, you'll need to put the following:
PHP Code:
<?php require('includes/country_checker.php'); ?>
Finally, because you were redirecting from index.php to whatever your actual home page is called, you'll want to create a 301 redirect from index.php to your actual home page; you could do this via PHP or via .htaccess.
See this tutorial for 301 redirect via various methods.
|
Look for the email on this.
And a big thank you for the help
|
|
|
|
05-28-2007, 02:22 PM
|
Re: GeoIP blocking of countries
|
Posts: 253
Name: Michel Samuel
|
Sorry to bring this back but I am banging my head on this issue.
I have the GEOIP installed and it is working according to what it is supposed to do.
I have deeplinking abilities prevented.
But still my american traffic is almost 5 times my desired traffic.
What else can I do?
What am I missing here?
|
|
|
|
05-28-2007, 03:25 PM
|
Re: GeoIP blocking of countries
|
Posts: 442
Name: Damien
|
How are you measuring the traffic - i.e. what specific measures are indicating the 5 times more american traffic etc.?
My guess would be that perhaps images etc. (i.e. content that is contained within your pages, but not the actual page itself) is causing the problem. The only way that you could block that is via .htaccess (I think?) - but that takes us back to whether to use .htaccess or a PHP script etc.
Without knowing specifically what the traffic is and how you're measuring it, then it's difficult to say what would be the best way to "cure" it.
Ideally, check the server access logs to determine what files are loaded by those americans, and what the referrer values are (i.e. are they slipping through the country check, or are they hotlinked images etc.).
__________________
Layershift :: DDS & Dedicated, UK & USA-based Managed Virtuozzo VPS, Reseller & Shared Hosting
Experienced Parallels Platinum Partners (Plesk since 2001, Virtuozzo since 2004)
|
|
|
|
05-29-2007, 06:47 AM
|
Re: GeoIP blocking of countries
|
Posts: 253
Name: Michel Samuel
|
Quote:
Originally Posted by damien_ls
How are you measuring the traffic - i.e. what specific measures are indicating the 5 times more american traffic etc.?
My guess would be that perhaps images etc. (i.e. content that is contained within your pages, but not the actual page itself) is causing the problem. The only way that you could block that is via .htaccess (I think?) - but that takes us back to whether to use .htaccess or a PHP script etc.
Without knowing specifically what the traffic is and how you're measuring it, then it's difficult to say what would be the best way to "cure" it.
Ideally, check the server access logs to determine what files are loaded by those americans, and what the referrer values are (i.e. are they slipping through the country check, or are they hotlinked images etc.).
|
I am blocking my deeplinks via the .htaccess file. (tested it, had many others test it.. it's working)
Now I'm using AWstats and unless I'm not reading the graphs right it shows my american traffic is still clocking in at 5xs my desired.
Now since installing the GEOIP. (thanks for the help) My bandwidth usage has dropped significantly.
The only thing I did notice is a heck of a lot of various bot activity.
|
|
|
|
|
« Reply to GeoIP blocking of countries
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|