搜索

首页  >  问答  >  正文

能否使用JavaScript来ping一个IP?

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

高洛峰高洛峰2897 天前766

全部回复(3)我来回复

  • 天蓬老师

    天蓬老师2017-04-10 15:13:08

    如评论所说, 浏览器无法构建自定义包, 所以不可能ping, js仅支持http.

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    <code>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);

     

      }

    }

    </code>

    https://github.com/jdfreder/pingjs
    转自:
    http://stackoverflow.com/questions/4282151/is-it-possible-to-ping-a-se...

    回复
    0
  • 大家讲道理

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

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

    回复
    0
  • 高洛峰

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

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

    回复
    0
  • 取消回复