取得客戶端+服務端IP及地理位置信息
IP:113.83.***.**
返回狀態:1
IP範圍Strat:113.83.0.0
IP範圍End:113.83.255.255
國:中國
省份:廣東
城市:惠州
區/縣:
線路:電信
類型:
描寫:
- /**
- * 取得客戶端+服務端IP及地理位置資訊Sina iplookup
- *
- * @Support:QQ 910111100 (JoY)
- * @Time: 2012.10.11 15:50:00 * @HZapi.com (http://www.hzapi.com/)
- *
- */
- //取得地理位置資訊
- function iplookup($ip=1){
- if($ip){ //客戶端
- $userip=egetip_joy(); //客戶端IP
- }else{ //服務端
- $domain=$_SERVER['HTTP_HOST'];
- $ip=gethostbynameuserip=gethostbynameuserip=gethostbyname ($domain);
- }
- //回傳Sina地理位置資訊
- $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); //過濾多餘字元
- $json_arr=json_decode($json,true) ;
- return $json_arr;
- }
- //取得IP
- function egetip_joy(){
- if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('IPTP_NLI)('HT) ))
- {
- $ip=getenv('HTTP_CLIENT_IP');
- }
- elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_FORWARDED_FOR')&&strcasecmp(getenv('HTy_FORW)> > {
- $ip=getenv('HTTP_X_FORWARDED_FOR');
- }
- elseif(getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown')&strcasecmp(getenv('REMOTE_ADDR'),'unknown'),
- > $ip=getenv('REMOTE_ADDR');
- }
- elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADn'. '))
- {
- $ip=$_SERVER['REMOTE_ADDR'];
- }
- $ip=preg_replace("/^([d.]+).*/","1 ",$ip);
- return $ip;
- }
- /**
- * 模擬JS裡的unescape
- *
- * @Support:QQ 910111100 (JoY)
- * @Time: 2012.09.29 15:50:00
- * @HZapi.com ://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)參數非空為取得伺服器端IP
-
- echo "IP:".egetip_joy()."
";
- echo '回傳狀態:'.$iplookup['ret']."
";
- echo 'IP範圍Strat:'.$iplookup['start']."
";
- echo 'IP範圍End:'.$iplookup['end']."
";
- echo '國家:'.unescape($iplookup['country'])."
";
- echo '省:'.unescape($iplookup['province'])."
";
- echo '城市:'.unescape($iplookup['city'])."
";
- echo '區/縣:'.unescape($iplookup['district']). "
";
- echo '線路:'.unescape($iplookup['isp'])."
";
- echo '類型:'.$iplookup['type']."
";
- echo '描寫:'.$iplookup['desc']."
";
- //print_r($iplookup);
-
-
- 複製程式碼
|