答案 0 :(得分:1)
没有。一个PHP脚本(在服务器上)很可能使用“ PHP Sockets”来实现。看一下 这个:https://www.php.net/manual/en/sockets.examples.php
否则它可以使用exec()函数,但这将是一个安全漏洞。
所以回答您的问题:网站将ping IP地址而不是“客户端”
答案 1 :(得分:0)
如果您要ping服务器,即实际的网址/网址(例如www.google.com),则可以查看此JSFiddle http://jsfiddle.net/GSSCD/203/或GitHub存储库https://github.com/jdfreder/pingjs。
这是来自JSFiddle的一些代码:
function Pinger_ping(ip, callback) {
if(!this.inUse) {
this.inUse = true;
this.callback = callback
this.ip = ip;
var _that = this;
this.img = new Image();
this.img.onload = function() {_that.good();};
this.img.onerror = function() {_that.good();};
this.start = new Date().getTime();
this.img.src = "http://" + ip;
this.timer = setTimeout(function() { _that.bad();}, 1500);
}
}
ping服务器/网址的另一种方法是使用JavaScript及其支持的XMLHttpRequest()
函数:
HTML:
<div id="result"></div>
JavaScript:
function http_ping(fqdn) {
var NB_ITERATIONS = 4; // number of loop iterations
var MAX_ITERATIONS = 5; // beware: the number of simultaneous XMLHttpRequest is limited by the browser!
var TIME_PERIOD = 1000; // 1000 ms between each ping
var i = 0;
var over_flag = 0;
var time_cumul = 0;
var REQUEST_TIMEOUT = 9000;
var TIMEOUT_ERROR = 0;
document.getElementById('result').innerHTML = "HTTP ping for " + fqdn + "</br>";
var ping_loop = setInterval(function() {
// let's change non-existent URL each time to avoid possible side effect with web proxy-cache software on the line
url = "http://" + fqdn + "/a30Fkezt_77" + Math.random().toString(36).substring(7);
if (i < MAX_ITERATIONS) {
var ping = new XMLHttpRequest();
i++;
ping.seq = i;
over_flag++;
ping.date1 = Date.now();
ping.timeout = REQUEST_TIMEOUT; // it could happen that the request takes a very long time
ping.onreadystatechange = function() { // the request has returned something, let's log it (starting after the first one)
if (ping.readyState == 4 && TIMEOUT_ERROR == 0) {
over_flag--;
if (ping.seq > 1) {
delta_time = Date.now() - ping.date1;
time_cumul += delta_time;
document.getElementById('result').innerHTML += "</br>http_seq=" + (ping.seq-1) + " time=" + delta_time + " ms</br>";
}
}
}
ping.ontimeout = function() {
TIMEOUT_ERROR = 1;
}
ping.open("GET", url, true);
ping.send();
}
if ((i > NB_ITERATIONS) && (over_flag < 1)) { // all requests are passed and have returned
clearInterval(ping_loop);
var avg_time = Math.round(time_cumul / (i - 1));
document.getElementById('result').innerHTML += "</br> Average ping latency on " + (i-1) + " iterations: " + avg_time + "ms </br>";
}
if (TIMEOUT_ERROR == 1) { // timeout: data cannot be accurate
clearInterval(ping_loop);
document.getElementById('result').innerHTML += "<br/> THERE WAS A TIMEOUT ERROR <br/>";
return;
}
}, TIME_PERIOD);
}
但是,当然,这些是网址,而不是IP地址,因此我不确定这是否是您的目标。我也不确定您是否在寻找获取连接所花费的时间以及发送和接收的数据包和字节的数量,还是只想验证连接。上面的代码完成了所有这些事情。对于IP地址,您可以尝试AJAX请求来ping服务器,该服务器仅查看是否使用您服务器的IP地址(而不是用户的客户端)进行连接,例如:
client --AJAX-- yourserver --ICMP ping-- targetservers
您也可以尝试:
isReachable
使用Java小程序ActionScript
)获取IP地址的最后一种假设性和非传统性的方法是检查并查看您提到的网站的来源,并复制一些代码(主要是JavaScript),并在您的终端对其进行测试并尝试实现它。