How to use ping - 10 common examples

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 suskind / network-list / src / index.js View on Github external
function getInfo(ip, callback) {
	const result = {
		ip,
		alive: false,
		hostname: null,
		mac: null,
		vendor: null,
        hostnameError: null,
        macError: null,
        vendorError: null,
	};
    // console.log(`Checking ${ip}...`);
    ping.promise.probe(ip, {
        timeout: options.timeout,
    }).then((res) => {
        if (res.alive) {
            result.alive = true;
            dns.reverse(ip, (err, host) => {
                if (err) {
                    result.hostnameError = 'Error on get hostname';
                } else {
                    result.hostname = (host && host.length) ? host[0] : null;
                }
                arp.getMAC(ip, (err2, mac) => {
                    if(err2 || !mac) {
                        result.macError = 'Error on get Mac address';
                    } else {
                        result.mac = mac.replace(/:([^:]{1}):/g, ':0$1:');
                    }
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 AlexGustafsson / homebridge-wol / lib / pinger.js View on Github external
async ping() {
    this.debugLog('Attempting to ping "%s" (%s)', this.config.name, this.config.ip || 'unknown ip');

    // Timeout is given in seconds
    const response = await ping.promise.probe(this.config.ip, {timeout: this.config.pingTimeout / 1000});
    this.debugLog('Result of pinging "%s" (%s): %s', this.config.name, this.config.ip || 'unknown ip', response.alive ? 'online' : 'offline');
    return response.alive;
  }
github jesusprubio / bluebox-ng / lib / protocols / ping.js View on Github external
new Promise((resolve, reject) => {
    const result = { up: false };
    const timeout = opts.timeout || 5000;
    const cliOpts = {
      timeout: timeout / 1000,
      // TODO: Add as parameter
      extra: ['-i', '2'], // 2 attempt
    };

    dbg('Starting, opts', cliOpts);
    cli.promise.probe(rhost, cliOpts)
    .then((res) => {
      dbg('Response received', res);

      // We're only sending one so if no max -> host down.
      if (res.alive) {
        result.up = true;
        // We only made one, so avg is the same and the parsing is easier.
        result.data = res.output;
      }

      resolve(result);
    })
    .catch(err => reject(err));
  });
github jesusprubio / bluebox-ng / lib / index / ping.js View on Github external
(rhost) => {
      const attempts = opts.attempts || 3;
      const reqCfg = {
        // TODO: Not working for values over > 2000
        // timeout: opts.timeout || 5000,
        extra: [`-i ${attempts.toString()}`],
      };

      return ping.promise.probe(rhost, reqCfg);
    },
    // TODO: Review
github apache / openmeetings / openmeetings-web / src / main / java / org / apache / openmeetings / web / room / nettest-base.js View on Github external
function _pingEnd(avg, _all) {
		_log($('<span></span>').append(lbls['ping.avg']).append(_value(avg, lbls['ms'])));
		_log($('<span></span>').append(lbls['ping.rcv']).append(_value(_all.length, '')));
		_log($('<span></span>').append(lbls['ping.lost']).append(_value(PINGS - _all.length, '')));
		_setResult(_value(avg, lbls['ms']))
	}
	function _restart(size) {
github apache / openmeetings / openmeetings-web / src / main / java / org / apache / openmeetings / web / room / nettest-base.js View on Github external
function _pingEnd(avg, _all) {
		_log($('<span></span>').append(lbls['ping.avg']).append(_value(avg, lbls['ms'])));
		_log($('<span></span>').append(lbls['ping.rcv']).append(_value(_all.length, '')));
		_log($('<span></span>').append(lbls['ping.lost']).append(_value(PINGS - _all.length, '')));
		_setResult(_value(avg, lbls['ms']))
	}
	function _restart(size) {
github apache / openmeetings / openmeetings-web / src / main / java / org / apache / openmeetings / web / room / nettest-base.js View on Github external
function _pingEnd(avg, _all) {
		_log($('<span></span>').append(lbls['ping.avg']).append(_value(avg, lbls['ms'])));
		_log($('<span></span>').append(lbls['ping.rcv']).append(_value(_all.length, '')));
		_log($('<span></span>').append(lbls['ping.lost']).append(_value(PINGS - _all.length, '')));
		_setResult(_value(avg, lbls['ms']))
	}
	function _restart(size) {
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;

ping

a simple wrapper for ping

MIT
Latest version published 7 months ago

Package Health Score

73 / 100
Full package analysis