Developer Tools
The Ipgp.net API is in continuous development, but so far we have a working XML API.
What Ipgp.net API provides:
- City
- Region
- Country
- ISP
- Country flag
How to use Ipgp.net API
UPDATE: Right now the IPGP Api works only with an API key. Use this form: http://www.ipgp.net/get-api-key/ to get your API Key and use it in the following way http://www.ipgp.net/api/xml/IPA_ADDRESS/API_KEY
The XML version of the api can be accesed on the following url: http://www.ipgp.net/api/xml/IPA_ADDRESS ( replace IP_ADDRESS with the IP address you want to lookup )
The api will return ip address information, such as: country code, country name, link to an image for the country flag, city, region, internet service provider, latitude and longitude.
The IP address details are returned in the following format:
There are many different ways to parse the XML depending on your programing language.
Make sure your webhosting meets all the necessary requirements, so that the script will run properly.
Below is an example on how to use the API results in PHP and display or store them on your website:
The ip address should be passed trough $ip variable in PHP, and the script puts into $iplookup variable and array containing the data retreived.
If you want to output data at a specific location, for example country code, write: echo $iplookup['code'] . If you want only to embed a script that will only print on the webpage the data, look at the other webmaster tools that will be made available soon on this website. The API version is very usefull because the data can be printed or used by programmers anywhere in the code, not only just as a simple output in a box, and it can be used in many different programming language.
Check this documentation later and you will get examples how to parse an XML file in other languages, if you use a specific language and you would like to know how you can parse the XML in that language. If you are skilled enough to parse the XML file in other languages that the ones listed below please send us the way you did and we will put it here to help others parse the IP lookup XML just by using the code provided.
UPDATE: Here is an easier way to query the IPGP API.
$xml = simplexml_load_file(‘http://www.ipgp.net/api/xml/IPADDRESS/APIKEY’);
Now everything you need is in the $xml variable. Use print_r($xml) to see what it contains.
<?php
// Put in the following variable the ip address you want to look-up. To get the ip address of your website visitors use: $ip = $_REQUEST['ip'];
$ip = ‘IP_ADDRESS’;
$file = “http://www.ipgp.net/api/xml/”. $ip .”API_KEY”;
global $predata;
function contents($parser, $data){
global $predata;
if($data) {
$predata[] = $data;
}
}
function startTag($parser, $data){
echo “”;
}
function endTag($parser, $data){
echo “”;
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, “startTag”, “endTag”);
xml_set_character_data_handler($xml_parser, “contents”);
$fp = fopen($file, “r”);
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die(“Error on line ” . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
// The returned data is an array, you can type print_r($iplookup) at the end of the code to see the array.
$iplookup['ip']=$predata[1];
$iplookup['code']=$predata[3];
$iplookup['country']=$predata[5];
$iplookup['flag']=$predata[7];
$iplookup['city']=$predata[9];
$iplookup['region']=$predata[11];
$iplookup['isp']=$predata[13];
$iplookup['latitude']=$predata[15];
$iplookup['longitude']=$predata[17];
// print_r($iplookup);
?>

