目標IP沒有裝任何web或者http應(yīng)用
能否用JavaScript來實現(xiàn)ping這樣的一個IP,功能類似與console下的ping ip
擁有18年軟件開發(fā)和IT教學(xué)經(jīng)驗。曾任多家上市公司技術(shù)總監(jiān)、架構(gòu)師、項目經(jīng)理、高級軟件工程師等職務(wù)。 網(wǎng)絡(luò)人氣名人講師,...
如評論所說, 瀏覽器無法構(gòu)建自定義包, 所以不可能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
轉(zhuǎn)自:
http://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-se...
1、自己實現(xiàn):寫個后臺API,然后前臺發(fā)送必要的參數(shù),再展示ping結(jié)果。
2、抓包:已有很多網(wǎng)站有此功能,直接爬蟲抓過來使用。(直接通過通過別人的網(wǎng)站功能來Ping)
3、使用第三方Ping的API,前段調(diào)用這個API實現(xiàn)ping.