开发者

PHP - get server to ping a visitors IP and return the ping in ms

开发者 https://www.devze.com 2023-04-08 08:47 出处:网络
I want to do as the title states. To ping a users IP and return a result in ms, for instance: Ping IP return 400ms.

I want to do as the title states. To ping a users IP and return a result in ms, for instance:

Ping IP return 400ms.

I have no idea how to do this but I expect it would be relatively simple. I have access to the开发者_运维技巧 exec() function and the functions similar to it as I will be running this script on a virtual private server.

Thanks in advance.


try this

<?php

$out = array();
exec('ping -c 4 '.$_SERVER['REMOTE_ADDR'], $out);
print_r($out);

?>


Try this:

<?php

$ip     = $_SERVER['SERVER_ADDR'];  // Get the IP address of the visitor
$result = system('ping -n 1 '.$ip, $retval); // the result contains the last line of the ping command.

if ($retval==0) echo "OK";
if ($retval==1) echo "NOT OK";

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号