node-net-ping:网平

  • p5_450283
    了解作者
  • 14.9KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-05 02:40
    上传日期
net-ping - 该模块实现了对ICMP Echo (ping) 支持。 此模块使用: npm install net-ping 它使用require()函数加载: var ping = require ("net-ping"); 然后可以创建一个 ping 会话来 ping 或跟踪到许多主机的路由: var session = ping.createSession (); session.pingHost (target, function (error, target) { if (error) console.log (target + ": " + error.toString ()); else console.log (target + ": Alive"); }); 网络协议支持 该模块支持使用 ICMP 的
node-net-ping-master.zip
  • node-net-ping-master
  • example
  • ping-retries-0.js
    635B
  • ping6.js
    816B
  • ping6-ttl.js
    890B
  • ping-response-time.js
    850B
  • ping-ttl.js
    891B
  • ping-packet-size.js
    787B
  • ping.js
    770B
  • trace-route.js
    1.1KB
  • README.md
    17.6KB
  • .hgignore
    28B
  • index.js
    13.9KB
  • package.json
    723B
内容介绍
# net-ping - [homepage][homepage] This module implements ICMP Echo (ping) support for [Node.js][nodejs]. This module is installed using [node package manager (npm)][npm]: npm install net-ping It is loaded using the `require()` function: var ping = require ("net-ping"); A ping session can then be created to ping or trace route to many hosts: var session = ping.createSession (); session.pingHost (target, function (error, target) { if (error) console.log (target + ": " + error.toString ()); else console.log (target + ": Alive"); }); [homepage]: http://re-tool.org "Homepage" [nodejs]: http://nodejs.org "Node.js" [npm]: https://npmjs.org/ "npm" # Network Protocol Support This module supports IPv4 using the ICMP, and IPv6 using the ICMPv6. # Error Handling Each request exposed by this module requires one or more mandatory callback functions. Callback functions are typically provided an `error` argument. All errors are sub-classes of the `Error` class. For timed out errors the error passed to the callback function will be an instance of the `ping.RequestTimedOutError` class, with the exposed `message` attribute set to `Request timed out`. This makes it easy to determine if a host responded, a time out occurred, or whether an error response was received: session.pingHost ("1.2.3.4", function (error, target) { if (error) if (error instanceof ping.RequestTimedOutError) console.log (target + ": Not alive"); else console.log (target + ": " + error.toString ()); else console.log (target + ": Alive"); }); In addition to the the `ping.RequestTimedOutError` class, the following errors are also exported by this module to wrap ICMP error responses: * `DestinationUnreachableError` * `PacketTooBigError` * `ParameterProblemError` * `RedirectReceivedError` * `SourceQuenchError` * `TimeExceededError` These errors are typically reported by hosts other than the intended target. In all cases each class exposes a `source` attribute which will specify the host who reported the error (which could be the intended target). This will also be included in the errors `message` attribute, i.e.: $ sudo node example/ping-ttl.js 1 192.168.2.10 192.168.2.20 192.168.2.30 192.168.2.10: Alive 192.168.2.20: TimeExceededError: Time exceeded (source=192.168.1.1) 192.168.2.30: Not alive The `Session` class will emit an `error` event for any other error not directly associated with a request. This is typically an instance of the `Error` class with the errors `message` attribute specifying the reason. # Packet Size By default ICMP echo request packets sent by this module are 16 bytes in size. Some implementations cannot cope with such small ICMP echo requests. For example, some implementations will return an ICMP echo reply, but will include an incorrect ICMP checksum. This module exposes a `packetSize` option to the `createSession()` method which specifies how big ICMP echo request packets should be: var session = ping.createSession ({packetSize: 64}); # Round Trip Times Some callbacks used by methods exposed by this module provide two instances of the JavaScript `Date` class specifying when the first ping was sent for a request, and when a request completed. These parameters are typically named `sent` and `rcvd`, and are provided to help round trip time calculation. A request can complete in one of two ways. In the first, a ping response is received and `rcvd - sent` will yield the round trip time for the request in milliseconds. In the second, no ping response is received resulting in a request time out. In this case `rcvd - sent` will yield the total time spent waiting for each retry to timeout if any. For example, if the `retries` option to the `createSession()` method was specified as `2` and `timeout` as `2000` then `rcvd - sent` will yield more than `6000` milliseconds. Although this module provides instances of the `Date` class to help round trip time calculation the dates and times represented in each instance should not be considered 100% accurate. Environmental conditions can affect when a date and time is actually calculated, e.g. garbage collection introducing a delay or the receipt of many packets at once. There are also a number of functions through which received packets must pass, which can also introduce a slight variable delay. Throughout development experience has shown that, in general the smaller the round trip time the less accurate it will be - but the information is still useful nonetheless. # Constants The following sections describe constants exported and used by this module. ## ping.NetworkProtocol This object contains constants which can be used for the `networkProtocol` option to the `createSession()` function exposed by this module. This option specifies the IP protocol version to use when creating the raw socket. The following constants are defined in this object: * `IPv4` - IPv4 protocol * `IPv6` - IPv6 protocol # Using This Module The `Session` class is used to issue ping and trace route requests to many hosts. This module exports the `createSession()` function which is used to create instances of the `Session` class. ## ping.createSession ([options]) The `createSession()` function instantiates and returns an instance of the `Session` class: // Default options var options = { networkProtocol: ping.NetworkProtocol.IPv4, packetSize: 16, retries: 1, sessionId: (process.pid % 65535), timeout: 2000, ttl: 128 }; var session = ping.createSession (options); The optional `options` parameter is an object, and can contain the following items: * `networkProtocol` - Either the constant `ping.NetworkProtocol.IPv4` or the constant `ping.NetworkProtocol.IPv6`, defaults to the constant `ping.NetworkProtocol.IPv4` * `packetSize` - How many bytes each ICMP echo request packet should be, defaults to `16`, if the value specified is less that `12` then the value `12` will be used (8 bytes are required for the ICMP packet itself, then 4 bytes are required to encode a unique session ID in the request and response packets) * `retries` - Number of times to re-send a ping requests, defaults to `1` * `sessionId` - A unique ID used to identify request and response packets sent by this instance of the `Session` class, valid numbers are in the range of `1` to `65535`, defaults to the value of `process.pid % 65535` * `timeout` - Number of milliseconds to wait for a response before re-trying or failing, defaults to `2000` * `ttl` - Value to use for the IP header time to live field, defaults to `128` After creating the ping `Session` object an underlying raw socket will be created. If the underlying raw socket cannot be opened an exception with be thrown. The error will be an instance of the `Error` class. Seperate instances of the `Session` class must be created for IPv4 and IPv6. ## session.on ("close", callback) The `close` event is emitted by the session when the underlying raw socket is closed. No arguments are passed to the callback. The following example prints a message to the console when the underlying raw socket is closed: session.on ("close", function () { console.log ("socket closed"); }); ## session.on ("error", callback) The `error` event is emitted by the session when the underlying raw socket emits an error. The following arguments will be passed to the `callback` function: * `error` - An instance of the `Error` class, the exposed `message` attribute will contain a detailed error message. The following example prints a message to the console when an error occurs with the underlying raw socket, the session is then closed: session.on ("error", function (error) { console.log (error.toString ());
评论
    相关推荐
    • contracts:Hermez网络协议智能合约
      智能合约 实施Hermez智能合约 安装 $ yarn install && cp .env.example .env ####添加预提交挂钩 $ git config core.hooksPath .githooks 可选的: cp .env.example .env 在此命令后将您的var添加到.env ...
    • diablo2-protocol:Diablo 2网络协议
      暗黑破坏神2的网络协议:为暗黑破坏神1.13和1.14创建客户端和服务器。 安装 npm install diablo2-protocol 用法 跟随机器人几行 const { createClientDiablo } = require ( 'diablo2-protocol' ) async function ...
    • node-net-pcp:RFC 6887
      端口控制协议 (PCP) 是一种计算机网络协议,它允许 IPv4 或 IPv6 网络上的主机控制传入的 IPv4 或 IPv6 数据包如何由执行网络地址转换 (NAT) 或数据包过滤的上游路由器转换和转发。 通过允许主机创建明确的端口转发...
    • fbp-protocol:基于流的编程网络协议的测试,方案和规范
      FBP网络协议 基于流的编程网络协议的测试,方案和规范。 您可以在找到规范的版本。 附带的测试套件为开发人员提供了一种简便的方法来测试其运行时与协议的兼容性。 还包括对运行时开发人员有用的文件,例如消息...
    • ps2-emu:PlanetSide 2 网络仿真 PoC
      注意:随着网络协议的不断发展,这些不太可能针对实时服务器开箱即用。 安装 安装 在项目文件夹中运行npm install 完整的客户端测试 此脚本测试登录和区域客户端功能。 首先,登录并获取lp-token cookie 值。 将...
    • node-net-snmp:简单网络管理协议(SNMP)JavaScript实现
      网络快照 该模块实现了版本1、2c和3。 用其他语言阅读:,。 该模块是使用: npm install net-snmp 它是使用require()函数加载的: var snmp = require ( "net-snmp" ) ; 快速开始 然后可以创建到远程主机的...
    • hsms:HSMS协议JavaScript驱动程序
      驱动程序可以执行标准所要求的每一项工作:定义使用TCP / IP网络协议的消息交换过程。 使用TCP / IP连接过程在实体之间建立通信链接 开发和维护在实体之间交换SECS消息所需的协议约定 使用TCP / IP发送和接收数据 ...
    • protoman:为不同目的创建自己的网络协议的框架
      ProtoMan 是一个有用的框架,可以为不同的目的创建自己的网络协议,例如 RPC、隧道等。 安装 你可以安装 protoman vim NPMnpm install protoman 用法 你可能想创建一个支持你自己协议的服务器,下面是一个例子...
    • net-oce-protocol:与 net-oce 对话的协议定义
      网络协议 livecad 和 net-oce 的 protobuf 定义和 javascript 客户端 安装 npm install --save net-oce-protocol 用 var createClient = require ( 'net-oce-protocol' ) // create a stream to a ...
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等