Results 1 to 6 of 6

Thread: How can I get the IP of different countries?

  1. #1
    Join Date
    Feb 2010
    Location
    India
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How can I get the IP of different countries?

    Need help to get ip of diffrent countries...


    please help..

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    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.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. The Following User Says Thank You to fileserverdirect For This Useful Post:

    victory.jeet (02-21-2010)

  4. #3
    Join Date
    Feb 2010
    Location
    India
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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.

  5. #4
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    I found this freeware script online:
    Put this in your functions page (or on the top of your page):
    PHP Code:
    <?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:
    PHP Code:
    <?
    $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:
    PHP Code:
    <?
    $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
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  6. The Following User Says Thank You to fileserverdirect For This Useful Post:

    victory.jeet (02-21-2010)

  7. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #6
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You can also check out 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 also has a free web service that you can utilize after signing up for a free account.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •