Showing posts with label ip address. Show all posts
Showing posts with label ip address. Show all posts

Saturday, September 08, 2012

Get location of an IP address

 GET LOCATION OF AN IP ADDRESS

   We can get the location (country name, country code, region name,city name) by using a simple json code below ... Enjoy it ... Thanks for jquery.com team.

 <?php
$ip = "122.174.119.205";
$json = file_get_contents("http://www.codehelper.io/api/ips/?ip=".$ip."&full=true");
$json = json_decode($json,true);
echo "<pre>";
print_r($json );
?>

RESULT


Array
(
    [IP] => 122.174.119.205
    [ContinentCode] => AS
    [ContinentName] => Asia
    [CountryCode2] => IN
    [CountryCode3] => IND
    [Country] => IN
    [CountryName] => India
    [RegionName] => Tamil Nadu
    [CityName] => Chennai
    [CityLatitude] => 13.0833
    [CityLongitude] => 80.2833
    [CountryLatitude] => 20
    [CountryLongitude] => 77
    [LocalTimeZone] => Asia/Calcutta
    [REMOTE_ADDR] => 198.199.93.153
    [HTTP_X_FORWARDED_FOR] => 122.174.119.205
    [CallingCode] => 91
    [Population] => 1,166,079,217 (2)
    [AreaSqKm] => 3,287,263 (8)
    [GDP_USD] => 3.297 Trillion (4)
    [Capital] => New Delhi
    [Electrical] => 230 V,50 Hz Type C Type D
    [Languages] => Hindi 41%, Bengali 8.1%, Telugu 7.2%, Marathi 7%, Tamil 5.9%, Urdu 5%, Gujarati 4.5%, Kannada 3.7%, Malayalam 3.2%, Oriya 3.2%, Punjabi 2.8%, Assamese 1.3%, Maithili 1.2%, other 5.9%
    [Currency] => Indian Rupee (INR)
    [Flag] => http://www.codehelper.io/api/ips/proips/flags/IN.jpg
)



Note:
If the url is not working  use this.It will display ISO2 (i.e) US (CountryCode2).

$iso2=exec("whois $ip | grep -i country | awk -F\":\" '{gsub(/[[:space:]]*/,\"\",\$2); print \$2}'");

Another one following example. Thanks for the code geoplugin.net .

<?php
$ip = "12.215.42.19";

$json2 = file_get_contents("http://www.geoplugin.net/php.gp?ip=".$ip."");
$data = unserialize($json2);
echo '<pre>';
print_r($data);

?>

RESULT

Array

(


    [geoplugin_request] => 12.215.42.19
    [geoplugin_status] => 206
    [geoplugin_city] => 
    [geoplugin_region] => 
    [geoplugin_areaCode] => 0
    [geoplugin_dmaCode] => 0
    [geoplugin_countryCode] => US
    [geoplugin_countryName] => United States
    [geoplugin_continentCode] => NA
    [geoplugin_latitude] => 38
    [geoplugin_longitude] => -97
    [geoplugin_regionCode] => 
    [geoplugin_regionName] => 
    [geoplugin_currencyCode] => USD
    [geoplugin_currencySymbol] => $
    [geoplugin_currencySymbol_UTF8] => $
    [geoplugin_currencyConverter] => 1

)