suchen

Heim  >  Fragen und Antworten  >  Hauptteil

能否使用JavaScript来ping一个IP?

目标IP没有装任何web或者http应用
能否用JavaScript来实现ping这样的一个IP,功能类似与console下的ping ip

高洛峰高洛峰2859 Tage vor751

Antworte allen(3)Ich werde antworten

  • 天蓬老师

    天蓬老师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...

    Antwort
    0
  • 大家讲道理

    大家讲道理2017-04-10 15:13:08

    1、自己实现:写个后台API,然后前台发送必要的参数,再展示ping结果。
    2、抓包:已有很多网站有此功能,直接爬虫抓过来使用。(直接通过通过别人的网站功能来Ping)
    3、使用第三方Ping的API,前段调用这个API实现ping.

    Antwort
    0
  • 高洛峰

    高洛峰2017-04-10 15:13:08

    不仅仅是没有组包功能,主要是没办法操作网络io设备

    Antwort
    0
  • StornierenAntwort