• Welcome to DNForum.com - Domain Investor Forum, Free Domain Marketplace and a community for 45+ domain pros
    If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the oldest global domain name community on the internet and continues to grow every day. There are over 45,000 domainers on DNForum doing everything from buying domains, selling domains, using our free in-house built tools, learning about domains and discussing domains. Take a minute and Register.

I want to ban all of Asia

Status
Not open for further replies.

prose

DNF Member
The Originals
Legacy Exclusive Member
Joined
Apr 18, 2004
Messages
380
Reaction score
0
Please help me. I remember reading about getting a IP range to domain database but is there anything easier. I'm okay if I ban the whole APNIC and black out Australia as well.
 
well, that's possible.Not so easy, but possible.
My solution: get the IP database from webhosting.info, and when the user visits your site get the user country, then continent.If the continent is banned, send him to google or whatever.
 
I was successful. I had to find all the asian country codes then basically check to see if that's who is visiting. Then I redirect them to google if they are from asia.

Here is a walkthrough. It skips small steps like unziping in your server, and placing the files in the same directory as your PHP conversion program.

All code was taken from various sources.


Download the IP to country database:
PHP:
http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip

Setup the Database:
PHP:
CREATE DATABASE country;
USE DATABASE country;
CREATE TABLE iptocountry
        (ip_from int(4) unsigned,
         ip_to int(4) unsigned,
         country_code2 char(2),
         country_code3 char(3),
         country_name varchar(50));

Convert the .CSV file to MySQL.
PHP:
<?
define("SOURCE_FILENAME", "ip-to-country.csv");
define("SEPERATOR_COL", ",");
define("SEPERATOR_ROW", "\n");

mysql_connect("localhost", "user", "pass");
mysql_select_db("country");
mysql_query("DELETE FROM iptocountry") or die (mysql_error());


/*
Open file for reading
*/
$fhFile     = fopen(SOURCE_FILENAME, "r") or die ("Error opening ".SOURCE_FILENAME);
$sData      = fread($fhFile, filesize(SOURCE_FILENAME));

$aData      = explode(SEPERATOR_ROW, $sData);

foreach($aData as $sRow) {
    $aRow = explode(SEPERATOR_COL, $sRow);
    /* Prepare values for query */
    foreach($aRow as $sKey => $sValue) {
        $sValue         = str_replace("\"", "", $sValue);
        $sValue         = addslashes($sValue);
        $aRow[$sKey]    = "'".$sValue."'";
    }
    list($sIpFrom, $sIpTo, $sCountryCode2, $sCountryCode3, $sCountryName) = $aRow;
    $sQuery = "INSERT INTO iptocountry
                                (ip_from,
                                 ip_to,
                                 country_code2,
                                 country_code3,
                                 country_name)
                            VALUES
                                 (".$sIpFrom.",
                                  ".$sIpTo.",
                                  ".$sCountryCode2.",
                                  ".$sCountryCode3.",
                                  ".$sCountryName."
                            );";

    mysql_query($sQuery) or die (mysql_error());
}
?>

ADD TO TOP OF INDEX or HEADER:
PHP:
<?
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
$asia=array("AF","BD","BT","IO","BN","KH","CN","TP","GU","HK","IN","ID","JP","KZ","KP","KR","KG","LA","MO","MY","MV","MN","MM","NR","NP","MP","PK","PW","PH","SG","LK","TJ","TW","TH","TM","SU","UZ","VM");


    // Establishing a database connection
    $dbh=mysql_connect("localhost","user","pass");
    mysql_select_db("country");


    // Query for getting visitor countrycode
    $country_query  = "SELECT country_code2,country_name FROM iptocountry ".
         "WHERE IP_FROM<=inet_aton('$REMOTE_ADDR') ".
          "AND IP_TO>=inet_aton('$REMOTE_ADDR') ";


    // Executing above query
    $country_exec = mysql_query($country_query);


    // Fetching the record set into an array
    $ccode_array=mysql_fetch_array($country_exec);


    // getting the country code from the array
    $country_code=$ccode_array['country_code2'];

$numElements = count($asia);

for($counter=0; $counter < $numElements; $counter++)
{
        if ($country_code==$asia[$counter]) {
header("Location: http://www.google.com/");
}
}


   // Closing the database connection
   mysql_close($dbh);


?>
 
well, that's possible.Not so easy, but possible.
My solution: get the IP database from webhosting.info, and when the user visits your site get the user country, then continent.If the continent is banned, send him to google or whatever.
 
Does the asian bring shit to you, How about banning your own ass :cheeky: ?
 
Status
Not open for further replies.
Back
Top Bottom