Xaddress is a service that enables IP based geographic identification.
Home • API • Contact

There are three ways to interface with Xaddress. The standard method is through the web interface. The data can be accessed programmatically using either the JSON or XML API.

If you run into any issues or have any questions about the APIs, let us know.

JSON API

The JSON API can be accessed via JavaScript. The JSON URL is:

http://svc.xaddress.com/json

Below is an example of how to use the service.

<script type="text/javascript" src="http://static.xaddress.com/api.js"></script> <script type="text/javascript"> function on_success(json_obj) { var request_address = json_obj['request_address']; var request_status = json_obj['request_status']; var latitude = json_obj['latitude']; var longitude = json_obj['longitude']; var country = json_obj['country_code']; var region = json_obj['region']; var city = json_obj['city']; var about = json_obj['geo_about']; }; function on_error() { alert('error'); }; _xaddress_lookup(on_success, on_error); </script>

ADVANCED JSON API

If you already have a set of JavaScript libraries for handling JSON calls then you can create a server-side proxy to enable access to the JSON API. We've provided a sample proxy written in PHP.

Once you have the proxy in place you can diretly reference the service at:

/xaddress.php

Here is some sample code that uses Prototype:

<script type="text/javascript" src="prototype.js"> </script> <script type="text/javascript"> var ajax = new Ajax.Request('/xaddress.php', { method: 'get', //parameters: 'ra=64.233.167.99', onSuccess: function(transport) { var response = transport.responseJSON; alert(response['city']); }, onFailure: function(){ alert('Something went wrong...') } }); </script>

XML API

The XML API can be accessed by any programming language. The format of the request and response are documented below.

REQUEST

The request is a simple HTML URL. The format of the url is:

http://svc.xaddress.com/rpc?ra=IPV4_ADDRESS

E.g., http://svc.xaddress.com/rpc?ra=64.233.167.99

RESPONSE

The response is a basic XML document. The format of the document is:

<?xml version="1.0" encoding="UTF-8"?> <xaddress_lookup> <request_address>64.233.167.99</request_address> <request_status>ok</request_status> <latitude>37.4192</latitude> <longitude>-122.0574</longitude> <country>US</country> <region>CA</region> <city>Mountain View</city> <geo_about>This product includes GeoLite data created by MaxMind</geo_about> </xaddress_lookup>

PHP EXAMPLE

The example implementation below assumes that both the CURL and XML libraries are compiled into PHP.

<?php $xaddress = lookup_location('68.174.153.141'); print("request_address: $xaddress->request_address\n"); print("request_status: $xaddress->request_status\n"); print("latitude: $xaddress->latitude\n"); print("longitude: $xaddress->longitude\n"); print("country: $xaddress->country\n"); print("region: $xaddress->region\n"); print("city: $xaddress->city\n"); print("geo_about: $xaddress->geo_about\n"); function lookup_location($remote_address) { $xaddress_url = "http://svc.xaddress.com/rpc?ra=$remote_address"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $xaddress_url); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 4); curl_setopt($curl, CURLOPT_TIMEOUT, 4); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); $data = curl_exec($curl); if (curl_errno($curl) != 0 || curl_getinfo($curl, CURLINFO_HTTP_CODE) == 404) { curl_close($curl); return false; } curl_close($curl); return new SimpleXMLElement($data); } ?>

This product includes GeoLite data created by MaxMind. This is a free service and doesn't provide a warranty of any kind.
© 2014 Deft Labs