🌐
经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用
点我优惠购买
🚀
拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多
点我优惠购买
🛡️
稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少
点我优惠购买
温馨提示:这篇文章已超过875天没有更新,请注意相关的内容是否还可用!
网站Ping接口源码,接口利用的百度开发接口制作,接口可查IP地址和网站测速。
API接口代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | <?PHP$hh=$_GET['hh']?:"\n";//换行符号(默认\n)if($_GET['url']==null){exit();}exit();}$msg = $_GET['url'];$host = $msg;$port = '80';$num = 2; //Ping次数$tip = gethostbyname($_GET['url']);//获取时间function mt_f (){list($usec,$sec) = explode(" ",microtime());return ((float)$usec + (float)$sec); //微秒加秒}function ping_f($host,$port){$time_s = mt_f();$ip = gethostbyname($host);$fp = @fsockopen($host,$port);if(!$fp)return '测试超时';$get = "GET / HTTP/1.1\r\nHost:".$host."\r\nConnect:".$port."Close\r\n";fputs($fp,$get);fclose($fp);$time_e = mt_f();$time = $time_e - $time_s;$time = ceil($time * 1000);return $time;}if(ping_f($host,$port)=='测试超时'){echo '测试超时,请检查目标站点是否正常!';}else{for($i = 0;$i < $num;$i++){if($i==0){$s1=$t.ping_f($host,$port);}elseif($i == 1){$s2=$t.ping_f($host,$port);}//每次运行中间间隔1Ssleep(1);//刷新输出缓存ob_flush();flush();}$se=json_decode(file_get_contents("http://opendata.bAIdu.com/api.php?query=".$tip."&co=&resource_id=6006&t=1433920989928&ie=utf8&oe=utf-8&format=json"),true);$dz=$se["data"][0]["location"];if($s1>$s2){echo '查询数据:'.$msg.''.$hh.'';echo 'IP地址:'.$tip.''.$hh.'';echo '主机地址:'.$dz.''.$hh.'';echo '最慢:'.$s1.'/ms'.$hh.'';echo '最快:'.$s2.'/ms'.$hh.'';echo '平均:'.(($s1-$s2)/2+$s2).'/ms';}else{echo '查询数据:'.$msg.''.$hh.'';echo 'IP地址:'.$tip.''.$hh.'';echo '主机地址:'.$dz.''.$hh.'';echo '最慢:'.$s1.'/ms'.$hh.'';echo '最快:'.$s2.'/ms'.$hh.'';echo '平均:'.(($s1-$s2)/2+$s2).'/ms';}}?> |
返回格式示例
1 | {"status":"0","t":"1433920989928","set_cache_time":"","data":[{"ExtendedLocation":"","OriginQuery":"114.158.169.85","appinfo":"","disp_type":0,"fetchkey":"114.158.169.85","location":"日本神奈川","origip":"114.158.169.85","origipquery":"114.158.169.85","resourceid":"6006","role_id":0,"shareImage":1,"showLikeShare":1,"showlamp":"1","titlecont":"IP地址查询","tplt":"ip"}]} |
美化下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | { "status": "0", "t": "1433920989928", "set_cache_time": "", "data": [{ "ExtendedLocation": "", "OriginQuery": "114.158.169.85", "appinfo": "", "disp_type": 0, "fetchkey": "114.158.169.85", "location": "日本神奈川", "origip": "114.158.169.85", "origipquery": "114.158.169.85", "resourceid": "6006", "role_id": 0, "shareImage": 1, "showLikeShare": 1, "showlamp": "1", "titlecont": "IP地址查询", "tplt": "ip" }]} |
使用方法:
此部分为隐藏内容,请输入验证码后查看
扫描右侧图片,或微信搜索 “ 网络财神 ” 或 “ newjixi ” 关注本站官方公众号,回复 “ 验证码 ” ,获取验证密码。
文章版权声明:除非注明,否则均为AI虎哥的工具库原创文章,转载或复制请以超链接形式并注明出处。



还没有评论,来说两句吧...