The code is quite simple, mainly using an address query interface from Youdao
function get_address_from_ip($ip)
{
$url='http://www.youdao.com/smartresult-xml/search.s?type=ip&q=';
$xml=file_get_contents($url.$ip);
$data=simplexml_load_string($xml);
return $data->product->location;
}