Heim > Fragen und Antworten > Hauptteil
目标IP没有装任何web或者http应用
能否用JavaScript来实现ping这样的一个IP,功能类似与console下的ping ip
天蓬老师2017-04-10 15:13:08
如评论所说, 浏览器无法构建自定义包, 所以不可能ping, js仅支持http.
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);
}
}
https://github.com/jdfreder/pingjs
转自:
http://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-se...
大家讲道理2017-04-10 15:13:08
1、自己实现:写个后台API,然后前台发送必要的参数,再展示ping结果。
2、抓包:已有很多网站有此功能,直接爬虫抓过来使用。(直接通过通过别人的网站功能来Ping)
3、使用第三方Ping的API,前段调用这个API实现ping.