UNPKG

domotz-remote-pawn

Version:

Domotz Agent

106 lines (95 loc) 3.72 kB
/** This file is part of Domotz Agent. * Copyright (C) 2016 Domotz Ltd * * Domotz Agent is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Domotz Agent is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>. **/ var netInfo = function (message, resourceLocator) { var step = resourceLocator.step; var time = resourceLocator.utils.time; var netInfo = resourceLocator.networkTools.netInfo; var myIpServiceAddress = resourceLocator.configuration.external_scripts.url_for_netinfo; var results = { stats: { start: new Date(), end: null, elapsed_milliseconds: null }, local_network: { servers: { dns: null, dhcp: null, gateway: null }, interfaces: null }, internet_access: { ip: { address: null, name: null }, provider: null } }; function finalize(callback) { results.stats.end = new Date(); results.stats.elapsed_milliseconds = time.getDiff(results.stats); callback(results); } return { describe: function () { return message.correlationId + " - netInfo "; }, execute: function (callback) { step(function (err) { if (err) { return callback(null, err); } netInfo.getDHCPServers('broadcast-dhcp-discover.nse', this.parallel()); netInfo.getExternalIPAddress(myIpServiceAddress, this.parallel()); netInfo.getInterfaces(this.parallel()); netInfo.getGateway(this.parallel()); netInfo.getDNSServers(this.parallel()); }, function (err, dhcpServers, ip, interfaces, gateway, dnsServers) { if (err) { console.error(err); console.debug("Continuing"); } results.local_network.servers.dhcp = dhcpServers; results.local_network.interfaces = interfaces; results.local_network.servers.gateway = gateway; results.local_network.servers.dns = dnsServers; results.internet_access.ip.address = ip || null; if (ip) { netInfo.getProvider(ip, this.parallel()); netInfo.getExternalIPName(ip, this.parallel()); } else { finalize(callback); } }, function (err, provider, externalIpName) { if (err) { console.error(err); console.debug("Continuing"); } results.internet_access.provider = provider; results.internet_access.ip.name = externalIpName; finalize(callback); } ); } }; }; module.exports.command = netInfo;