Obtain client + server IP address and geographic location information IP address: 113. 83 .***.** Returned status: 1 IP address range: Strat: 113.83.0.0 IP address range: End: 113.83.255.255 Country: China Province: Guangdong City: Huizhou District/county: Line: China Telecom Type: Description:
- /**
- * Obtain the client + server IP address and geographic location information Sina iplookup
- *
- * @ Support: QQ 910111100 (JoY)
- * @ Time: 2012.10.11 15:50:00
- * @ HZapi.com (http://www.hzapi.com /)
- *
- */
- // Obtain geographic location information
- Function iplookup ($ ip = 1 ){
- If ($ ip) {// client
- $ Userip = egetip_joy (); // client IP address
- } Else {// server
- $ Domain = $ _ SERVER ['http _ host'];
- $ Userip = gethostbyname ($ domain );
- }
- // Returns the location information of 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); // filter extra characters
- $ Json_arr = json_decode ($ json, true );
- Return $ json_arr;
- }
- // Obtain the IP address
- 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 (); // The parameter iplookup (1) is not empty.
-
- Echo "IP:". egetip_joy ()."
";
- Echo 'return status: '. $ iplookup ['ret']."
";
- Echo 'IP range Strat: '. $ iplookup ['start']."
";
- Echo 'IP range End: '. $ 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 );
|