Web Hosting Info

Search:

featured partner

The IP to Country Database

  Forum Topics : Support / IP Addresses for Nigeria
Submitted by yorktown on Sun, 11/09/2003 - 23:05.
I've downloaded the CSV database and I want to block Nigeria. I'm getting alot of credit card fraud. I looked at your ranges example: 3258338624 to 3258338703 and I have 2 questions:

1) How do I convert this to the IP address. Not all IP's are 123.456.78.90 , some are, 12.3.456.7, etc.

2) The IP in question, 217.78.73.204, does not appear in the range for Nigeria in the CSV file but shows up as Nigerian when I run a query with your demo.

Please advise.
Comment viewing options:
Select your preferred way to display the comments and click 'Save settings' to submit your changes.
Solved it...Fast way to do it in Excel
Posted by yorktown on Mon, 11/10/2003 - 00:33.
Its actually easy to do Item 1 in Excel/MS Access:
Start With Column E (Columns A though D will end up being the IP Address: A.B.C.D)

Col A is the formulae: @floor([Column E]/16777216,1)
Col B is the formulae: @floor([Column F]/65536,1)
Col C is the formulae: @floor([Column G]/256,1)
Col D is the formulae: @floor[Column H]

Col E is the IP Number
Col F is a Formulae: @sum([Column E] - ([Column A] * 16,777,216))
Col G is a Formulae: @sum((Column F] - ([Column B] * 65536)))
Col H is a formulae: @sum([Column G] - ([Column C] * 256))

You can, of cource, copy the formulaes and then paste them as many columns below that in Excel so ift performs the same function over and over.

Take Columns A, B, C and D and copy it. Go to word, select EDIT and "Paste Special" (as TEXT)

Hit CTRL-H. (Find and Relplace)
Enter ^t in the top and . in the bottom. That will replace all the tabs with decimal points. You then have ALL of the IP addresses to copy and paste back into Excel or wherever you want.
 
Excel formula problem
Posted by buhbuhl on Sun, 08/15/2004 - 05:38.
Hi, I'm using Excel 2003 and tried to implement your solution against the ip-to-country.csv file, but didn't get very far. Here's what I had.

cell A1
=FLOOR(E10/16777216,1)

cell B1
=FLOOR(F10/65536,1)

cell C1
=FLOOR(G10/256,1)

cell D1
=FLOOR(H10/1,1) Had to change formula because of error
message:
"You have entered too few arguments for this
function."

cell E1
33996344

the formula to for 'Col F' I'm not sure how to get it to work.
I wound up with:
@sum(E1 - (A1 * 16,777,216))
which still produces an error
column E is the start IP column listed in the ip-to-country.csv

Thanks in advace...
Hi yorktown You can simply
Posted by amit on Mon, 11/10/2003 - 02:47.
Hi yorktown
You can simply modify the code provided in our handbook - Example code to detect country to block Nigeria...

After the line

$country_code=$ccode_array['country_code2'];

Just type :

if ($country_code=="NG")
{
header("Location: http://www.domain/your-blocked-page.htm");
}

and then just close the data base connection.
You dont really need to bother about the exact IP Ranges of Nigeria :-)
-
Amit Bhawnani
another humble employee.
RTFM
Posted by Mins on Tue, 11/11/2003 - 23:15.
Have you even read the manual?? :-)
In PHP 4 you can use the following to convert a dotted IP Address to its corresponding IP Number:

$ip_number = sprintf("%u", ip2long($dotted_ip_address));

and this to convert IP Number to its corresponding dotted IP Address:

$dotted_ip_address = long2ip($ip_number);

and

//Warning PHP code!

//---------------------------------------------------
// Sample code to display Visitor Country information
// PHP 4
//---------------------------------------------------


// Establishing a database connection
$dbh=mysql_connect
("localhost:3306","$MYSQL_USERNAME","$MYSQL_PASSWORD");
mysql_select_db("$MYSQL_DBNAME");


// Query for getting visitor countrycode
$country_query = "SELECT country_code2,country_name FROM iptoc ".
"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'];


// getting the country name from the array
$country_name=$ccode_array['country_name'];


// Display the Visitor coountry information
echo "$country_code - $country_name";


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




:-))))))))))))


Min's

  • La vie est une maladie mortelle sexuellement transmissible
  • Life is a letal desease sexually transmissible Corret me if it's a bad translation... ;-)