Log in

View Full Version : How can I get the IP of different countries?



victory.jeet
02-15-2010, 07:34 AM
Need help to get ip of diffrent countries...


please help..

fileserverdirect
02-16-2010, 02:57 AM
You need to provide more information to help us answer your question

What exactly are you trying to do? Take a user's IP address and determine what county it is from in a php script, or just a website to do it. OR do you just want to find the county's IP range? Please be more specific.

victory.jeet
02-16-2010, 02:30 PM
I want the ip address script that can find the ip of diffrent countries like england and Ireland.

My requirement is that i want to show specific module not other then England and Ireland.

fileserverdirect
02-16-2010, 09:19 PM
I found this freeware script online:
Put this in your functions page (or on the top of your page):


<?php
function locateIp($ip){
$d = file_get_contents("http://www.ipinfodb.com/ip_query.php?ip=$ip&output=xml&timezone=false");

//Use backup server if cannot make a connection
if (!$d){
$backup = file_get_contents("http://backup.ipinfodb.com/ip_query.php?ip=$ip&output=xml&timezone=false");
$answer = new SimpleXMLElement($backup);
if (!$backup) return false; // Failed to open connection
}else{
$answer = new SimpleXMLElement($d);
}

$country_code = $answer->CountryCode;
$country_name = $answer->CountryName;
$region_name = $answer->RegionName;
$city = $answer->City;
$zippostalcode = $answer->ZipPostalCode;
$latitude = $answer->Latitude;
$longitude = $answer->Longitude;

//Return the data as an array
return array('ip' => $ip, 'country_code' => $country_code, 'country_name' => $country_name, 'region_name' => $region_name, 'city' => $city, 'zippostalcode' => $zippostalcode, 'latitude' => $latitude, 'longitude' => $longitude);
}
?>

And this on your page you want to use it:


<?
$ip = "74.125.45.100";
$ip_data = locateIp($ip);

echo "IP : " . $ip_data['ip'] . "\n";
echo "Country code : " . $ip_data['country_code'] . "\n";
echo "Country name : " . $ip_data['country_name'] . "\n";
echo "Region name : " . $ip_data['region_name'] . "\n";
echo "City : " . $ip_data['city'] . "\n";
echo "Zip/postal code : " . $ip_data['zippostalcode'] . "\n";
echo "Latitude : " . $ip_data['latitude'] . "\n";
echo "Longitude : " . $ip_data['longitude'] . "\n";
?>

Here is an example I made based on the API:


<?
$ip=$_SERVER['REMOTE_ADDR'];
$ip_data = locateIp($ip);

echo "The IP " . $ip_data['ip'];
if($ip_data['country_name']=="England") echo " is from England";
elseif($ip_data['country_name']=="Ireland") echo " is from Ireland";
?>

You don't need to download anything else BTW unless you want to host the API on your site, you can go HERE (http://ipinfodb.com/ip_location_api.php)

djr33
02-17-2010, 02:47 AM
http://www.maxmind.com/app/ip-location

The above may work, but another option is maxmind GeoIP. I've used it and it works well. They have a free version and a paid version which is a little more accurate.

They have example scripts in various languages (including PHP).

mialye
03-19-2010, 08:01 AM
You can also check out IP2Location.com (http://www.ip2location.com) which has the data as well as a web service that you can use to find the country from the IP address.

FraudLabs.com (http://www.fraudlabs.com) also has a free web service that you can utilize after signing up for a free account.