Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:');
}
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;
}
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));
});
(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
const p1 = new Promise((resolve, reject) => {
ping.promise.probe(ip, {
timeout: 1,
min_reply: 1
})
.then(res => {
resolve(res.alive)
})
})
testPing: function(ip) {
var self = this;
var ping = require('ping');
return ping.promise.probe(ip)
.then(function (res) {
if (!res.alive)
throw new String(ip + ' is not reachable.');
return true;
});
},
testSSH: function(ip, user) {
'use strict';
const ping = require('ping').promise;
const Command = require('../../models/Command.js');
const { timeDeltaToString, games } = require('../../CommonFunctions.js');
const d2Hosts = [
'bungie.net',
'api.steampowered.com',
'xbl.io',
'vlkyrie-superi.us',
'status.vlkyrie-superi.us',
];
const wfHosts = [
'warframe.com',
'api.warframestat.us',
'hub.warframestat.us',
'drops.warframestat.us',
function pingHost() {
return ping.promise.probe(PINGABLE_HOST, PING_CONFIG);
}
static async hostIsAccessible(host) {
return (await ping.promise.probe(host, {extra: ['-i 2']})).alive;
}
module.exports = async hostName => {
try {
let pingResponse = await ping.promise.probe(hostName);
return pingResponse.alive;
} catch (exception) {
return false;
}
};