How to use the ping.sys function in ping

To help you get started, we’ve selected a few ping examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eshengsky / HostsDock / public / javascript / index.js View on Github external
for (; batchStart < max; batchStart++) {
                    if (batchStart >= lineCount) {
                        return;
                    }

                    const line = this.editor.session.getLine(batchStart).trim();
                    const batchDone = batchStart === (max - 1);

                    // exclude blank or comment line
                    if (!line || line.startsWith('#')) {
                        cb(line, batchStart, batchDone);
                    } else {
                        const matched = line.match(reg);
                        if (matched && matched.length === 3) {
                            const ip = matched[1];
                            ping.sys.probe(ip, ipHandler(batchStart, line, cb, batchDone));
                        } else {
                            cb(line, batchStart, batchDone);
                        }
                    }
                }
            };
github jesusprubio / bluebox-ng / lib / modules / old / ping.js View on Github external
module.exports.run = (options, callback) => {
  // Not working
  // ping.promise.probe(
  //    options.target,
  //    {
  //        timeout: options.timeout,
  //        extra: [
  //            '-i ' + options.interval
  //        ]
  //    }
  // ).then(function (res) {
  //    callback(null, res);
  // })
  // .done();
  ping.sys.probe(options.target, alive => {
    callback(null, {
      alive,
    });
  });
};
github physiii / open-automation / controllers / gateway.js View on Github external
function check_connection() {
  var ping = require ("ping");
  host = "8.8.8.8";
  ping.sys.probe(host, function(isAlive) {
    var msg = isAlive ? 'alive' : 'dead';
    if (msg == 'dead') {
      bad_connection++;
      console.log('bad_connection',bad_connection);
      if (!ap_mode && bad_connection > 1) {
        var interfaces_file = "allow-hotplug wlan0\n"
                   + "iface wlan0 inet static\n"
    		   + "address 172.24.1.1\n"
    		   + "netmask 255.255.255.0\n"
    		   + "network 172.24.1.0\n"
    		   + "broadcast 172.24.1.255\n";
        fs.writeFile("/etc/network/interfaces", interfaces_file, function(err) {
          if(err) return console.log(err);
          console.log("Interface file saved, starting AP");
          exec("sudo ifdown wlan0 && sudo ifup wlan0 && sudo service dnsmasq restart && sudo hostapd /etc/hostapd/hostapd.conf");
          ap_mode = true;
github bitfocus / companion / lib / module / eventmaster / eventmaster.js View on Github external
instance.prototype.retry = function() {
	var self = this;

	if (self.eventmaster === undefined || (self.config !== undefined && self.config.host !== undefined && self.config.host.match(/^\d+\.\d+\.\d+\.\d+$/)) ) {
		if (self.eventmaster === undefined || (self.eventmaster.ip !== undefined && self.config.host !== self.eventmaster.ip)) {

			var check = checkIp(self.config.host);
			if (check.isValid === true) {
				var cfg = {
					timeout: 4,
				};
				ping.sys.probe(self.config.host, function(isAlive){
					if (isAlive == true) {
						debug("START WITH", self.config.host);
						self.eventmaster = new EventMaster(self.config.host);
						self.status(0);
						log('info', 'Connecting to '+self.config.host)
						debug('host', self.config);
					}
					else {
						self.status(2, 'No ping reply from '+self.config.host);
						log('error','No ping reply from '+self.config.host+'??')
					}
				}, cfg);
			}
		}
	}
	self.actions();
github normen / homebridge-bravia / index.js View on Github external
try {
      _json = JSON.parse(chunk);
      if (!isNull(_json) && !isNull(_json.result[0]) && _json.result[0].status === "active") {
        that.updatePowerState(true);
        if (!isNull(callback)) callback(null, true);
      } else {
        that.updatePowerState(false);
        if (!isNull(callback)) callback(null, false);
      }
    } catch (e) {
      that.updatePowerState(false);
      if (!isNull(callback)) callback(null, false);
    }
  };
  try {
    ping.sys.probe(that.ip, function(isAlive) {
      if (isAlive) {
        var post_data = '{"id":2,"method":"getPowerStatus","version":"1.0","params":[]}';
        that.makeHttpRequest(onError, onSucces, "/sony/system/", post_data,false);
      } else {
        that.updatePowerState(false);
        if (!isNull(callback)) callback(null, false);
      }
    });
  } catch (globalExcp) {
    that.updatePowerState(false);
    if (!isNull(callback)) callback(null, false);
  }
}
github Matten-Matten / ioBroker.enigma2 / vuplus.js View on Github external
function checkStatus() {
    ping.sys.probe(adapter.config.IPAddress, function (isAlive) {
        if (isAlive) {
            getResponse ("GETSTANDBY", 1, "/web/powerstate", evaluateCommandResponse);
            getResponse ("GETINFO", 1, "/web/about", evaluateCommandResponse);
            getResponse ("GETVOLUME", 1, "/web/vol", evaluateCommandResponse);
            getResponse ("GETCURRENT", 1, "/web/getcurrent", evaluateCommandResponse);
        } else {
            adapter.log.debug("VUPlus: " + adapter.config.IPAddress + " is not reachable!");
        }
    });
}
github SeydX / homebridge-fritz-platform / src / accessories / presence.js View on Github external
return new Promise(resolve => {

      ping.sys.probe(address, isAlive => {
        
        let state = isAlive ? 1 : 0;
        
        this.debug(this.accessory.displayName + ': is ' + (isAlive ? 'alive' : ' dead'));
        
        resolve(state);
      
      },{timeout: 1});
 
    });
github ianperrin / MMM-NetworkScanner / node_helper.js View on Github external
this.config.devices.forEach( function(device) {
            self.log(self.name + " is checking device: ", device.name);
            if ("ipAddress" in device) {
                self.log(self.name + " is pinging ", device.ipAddress);
                ping.sys.probe(device.ipAddress, function(isAlive) {
                    device.online = isAlive;
                    self.log(self.name + " ping result: ", [device.name, device.online] );
                    if (device.online) {
                        discoveredDevices.push(device);
                    }
                    self.sendSocketNotification("IP_ADDRESS", device);
                });
            }
        });
github cfry / dde / robot.js View on Github external
start(job_instance){
        //out("robot start called with job: " + job_instance.name)
        let sim_actual = Robot.get_simulate_actual(this.simulate)
        let this_robot = this
        let this_job   = job_instance
        if ([false, "both"].includes(sim_actual)) {
                let ping = require('ping') //https://www.npmjs.com/package/ping
                ping.sys.probe(this.ip_address,
                                function(isAlive){
                                    if (isAlive) {
                                        setTimeout(function(){this_robot.start_aux(this_job)},
                                                  500) //in case dexster is booting up, give it a chance to complete boot cycle
                                        //this_robot.use_ping_proxy(job_instance)
                                    }
                                    else {
                                        this_job.stop_for_reason("errored", "Could not connect to Dexter.\nIf it is because Dexter is initializing,\ntry again in a minute.")
                                    }
                                },
                               {timeout: 10}
                               )
        }
        else { setTimeout(function(){this_robot.start_aux(this_job)},
                         500) } //no actual connection to Dexter needed as we're only simulating, BUT
                                 //to keep similation as much like non-sim. due the same timeout.
github cfry / dde / robot_utilities.js View on Github external
function ping_a_dexter_scan_aux(net_address, host = 0, connected_count=0){
    if (host < 10) {
        let ip_address = net_address + host
        ping.sys.probe(ip_address, function(isAlive){
            if (isAlive) {
                connected_count += 1
                out(ip_address + " is connected. " +
                    `<a title="Insert into the editor,
a definition for the Dexter
at this ip address." href="#"> Insert Dexter definition </a>`)
            }
            //else if ((host % 32) == 0) { out("<br>.") }
            else {
                //out(ip_address + " is not connected.", "purple", true)
                output_is_not_connected_message(ip_address)
            }
            if(host == 255) {
                out("ping scan complete. " + connected_count + " connected host(s) found.")
                ping_a_dexter_ongoing = false
            }
            else if(ping_a_dexter_ongoing){

ping

a simple wrapper for ping

MIT
Latest version published 1 year ago

Package Health Score

66 / 100
Full package analysis