value(): number { if (this._value === undefined) { let vmOui = 0; let interfaceCount = 0; const interfaces = networkInterfaces(); for (let name in interfaces) { if (Object.prototype.hasOwnProperty.call(interfaces, name)) { for (const { mac, internal } of interfaces[name]) { if (!internal) { interfaceCount += 1; if (this._isVirtualMachineMacAdress(mac.toUpperCase())) { vmOui += 1; } } } } } this._value = interfaceCount > 0 ? vmOui / interfaceCount : 0; } return this._value; }
return machineId().catch(() => { // In case MachineId fails const hash = crypto.createHash('sha256') const network = os.networkInterfaces() hash.update(os.arch() + os.hostname() + os.platform() + os.type() + network['mac']) return hash.digest('hex') })
export function networkInterfaces() { const os = require('os'); const ifaces = os.networkInterfaces(); const faces = []; Object.keys(ifaces).forEach(function (ifname) { let alias = 0; ifaces[ifname].forEach(function (iface) { if ('IPv4' !== iface.family || iface.internal !== false) { // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses return; } if (alias >= 1) { faces.push({name: ifname + ':' + alias, address: iface.address}); // this single interface has multiple ipv4 addresses } else { // this interface has only one ipv4 adress faces.push({name: ifname, address: iface.address}); } ++alias; }); }); return faces; }
handler: () => ({ hostname: os.hostname(), arch: os.arch(), platfoirm: os.platform(), cpus: os.cpus().length, totalmem: humanize.filesize(os.totalmem()), networkInterfaces: os.networkInterfaces() })
function getIpAddress(): string { const interfaces = networkInterfaces(); let ips: string[] = Object.keys(interfaces) .reduce((results, name) => results.concat(interfaces[name]), []) .filter((iface) => iface.family === "IPv4" && !iface.internal) .map((iface) => iface.address); return ips[0] ? ips[0] : "unknown"; }
function bindingOutput(port: number) { let networkInterfaces = os.networkInterfaces(); for (let key in networkInterfaces) { let items = networkInterfaces[key]; let validItems = items.filter(item => item.family === 'IPv4'); for (let validInterface of validItems) console.log(`Listening on ${validInterface.address}:${port}`); } }
export default function () { // TODO(architect): Delete this test. It is now in devkit/build-webpack. const firstLocalIp = _(os.networkInterfaces()) .values() .flatten() .filter({ family: 'IPv4', internal: false }) .map('address') .first(); const publicHost = `${firstLocalIp}:4200`; const localAddress = `http://${publicHost}`; return Promise.resolve() // Disabling this test. Webpack Dev Server does not check the hots anymore when binding to // numeric IP addresses. // .then(() => ngServe('--host=0.0.0.0')) // .then(() => request(localAddress)) // .then(body => { // if (!body.match(/Invalid Host header/)) { // throw new Error('Response does not match expected value.'); // } // }) // .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }) .then(() => ngServe('--host=0.0.0.0', `--public-host=${publicHost}`)) .then(() => request(localAddress)) .then(body => { if (!body.match(/<app-root><\/app-root>/)) { throw new Error('Response does not match expected value.'); } }) .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }) .then(() => ngServe('--host=0.0.0.0', `--disable-host-check`)) .then(() => request(localAddress)) .then(body => { if (!body.match(/<app-root><\/app-root>/)) { throw new Error('Response does not match expected value.'); } }) .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }) .then(() => ngServe('--host=0.0.0.0', `--public-host=${localAddress}`)) .then(() => request(localAddress)) .then(body => { if (!body.match(/<app-root><\/app-root>/)) { throw new Error('Response does not match expected value.'); } }) .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }) .then(() => ngServe('--host=0.0.0.0', `--public-host=${firstLocalIp}`)) .then(() => request(localAddress)) .then(body => { if (!body.match(/<app-root><\/app-root>/)) { throw new Error('Response does not match expected value.'); } }) .then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; }); }
function getMac() { const interfaces = os.networkInterfaces() return Object.keys(interfaces).reduce((acc, key) => { if (acc) { return acc } const i = interfaces[key] const mac = i.find(a => a.mac !== '00:00:00:00:00:00') return mac ? mac.mac : null }, null) }
function listInterfaces() { const netInterfaces = os.networkInterfaces(); const keys = _.keys(netInterfaces); const res = []; for (const name of keys) { res.push({ name: name, addresses: netInterfaces[name] }); } return res; }
return new Promise<Location>((resolve, reject) => { let ifaces = os.networkInterfaces(); for (let ifacePos in ifaces) { ifaces[ifacePos].forEach(iface => { if (iface.family === 'IPv4' && !iface.internal) { logger.debug('mac address:', iface.mac); location.macAddress = iface.mac; resolve(location); } }); } });