网站Ping接口源码IP地址+测速

网站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){

echo "请输入参数!";

exit();

}

if (preg_match('/http:\/\//i'$_GET['url'])|preg_match('/https:\/\//i'$_GET['url'])) {

echo '不能带http://或https://,只需要输入域名!';

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);

}

//每次运行中间间隔1S

sleep(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"

    }]

}

使用方法:http://winvvv.com/tool/ping.php?url=che0.com&hh=%3Cbr%3E&num=3

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

执刀人的工具库

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值