Obtain client + server IP and geographical location information
IP: 113.83.***.**
Return status: 1
IP range Strat: 113.83.0.0
IP Range End: 113.83.255.255
Country: China
Province: Guangdong
City: Huizhou
District/County:
Line: Telecom
Type:
Description:
- /**
- * Get client + server IP and geographical location information Sina iplookup
- *
- * @Support: QQ 910111100 (JoY)
- * @Time: 2012.10.11 15:50:00
- * @HZapi.com (http:/ /www.hzapi.com/)
- *
- */
- //Get geographical location information
- function iplookup($ip=1){
- if($ip){ //Client
- $userip=egetip_joy(); // Client IP
- }else{ //Server
- $domain=$_SERVER['HTTP_HOST'];
- $userip=gethostbyname($domain);
- }
- //Return Sina geographical location information
- $json=@file_get_contents( 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='.$userip);
- $patterns = array();
- $patterns[0] = '/var remote_ip_info = /';
- $patterns[1] = '/;/';
- $patterns[2] = '/Wu/';
- $find = array();
- $find[0] = "";
- $ find[1] = "";
- $find[2] = "%u";
- $json = preg_replace($patterns, $find, $json); //Filter extra characters
- $json_arr=json_decode($json, true);
- return $json_arr;
- }
- //Get IP
- function egetip_joy(){
- if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown'))
- {
- $ip= getenv('HTTP_CLIENT_IP');
- }
- elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown'))
- {
- $ip=getenv('HTTP_X_FORWARDED_FOR');
- }
- elseif( getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown'))
- {
- $ip=getenv('REMOTE_ADDR');
- }
- elseif(isset($_SERVER['REMOTE_ADDR'])&&$ _SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown'))
- {
- $ip=$_SERVER['REMOTE_ADDR'];
- }
- $ip=preg_replace("/^([d. ]+).*/","1",$ip);
- return $ip;
- }
- /**
- * Simulate unescape in JS
- *
- * @Support: QQ 910111100 (JoY)
- * @Time: 2012.09.29 15:50:00
- * @HZapi.com (http://www.hzapi.com/)
- * echo unescape('%u4e1c%u6e56%u82b1%u56ed4%u53f7%u5c0f%u533a');
- */
- function unescape($str) {
- $str = rawurldecode($str);
- preg_match_all("/(?:%u.{4})|.{4};|d+;|.+/U",$str,$r);
- $ar = $r[0];
- foreach($ar as $k=>$v) {
- if(substr($v,0,2) == "%u")
- {
- $ar[$k] = iconv("UCS-2 ","utf-8//IGNORE",pack("H4",substr($v,-4)));
- }
- elseif(substr($v,0,3) == "")
- {
- $ar[$k] = iconv("UCS-2","utf-8",pack("H4",substr($v,3,-1)));
- }
- elseif(substr($v, 0,2) == "")
- {
- echo substr($v,2,-1)."";
- $ar[$k] = iconv("UCS-2","utf-8" ,pack("n",substr($v,2,-1)));
- }
- }
- return join("",$ar);
- }
-
-
- $iplookup=iplookup(); //iplookup (1) The parameter is not empty to obtain the server IP
-
- echo "IP:".egetip_joy()."
";
- echo 'Return status:'.$iplookup['ret']."
- echo 'IP range Strat:'.$iplookup['start']."
";
- echo 'IP rangeEnd:'.$iplookup['end']."
" ;
- echo 'Country:'.unescape($iplookup['country'])."
";
- echo 'Province:'.unescape($iplookup['province'])."
" ;
- echo 'City:'.unescape($iplookup['city'])."
";
- echo 'District/County:'.unescape($iplookup['district'])."
- echo 'Line:'.unescape($iplookup['isp'])."
";
- echo 'Type:'.$iplookup['type']."
";
- echo 'Description:'.$iplookup['desc']."
";
- //print_r($iplookup);
Copy code
|