當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript os.networkInterfaces函數代碼示例

本文整理匯總了TypeScript中os.networkInterfaces函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript networkInterfaces函數的具體用法?TypeScript networkInterfaces怎麽用?TypeScript networkInterfaces使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了networkInterfaces函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: value

	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;
	}
開發者ID:Chan-PH,項目名稱:vscode,代碼行數:25,代碼來源:id.ts

示例2: machineId

 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')
 })
開發者ID:alexsandrocruz,項目名稱:botpress,代碼行數:7,代碼來源:stats.ts

示例3: networkInterfaces

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;
}
開發者ID:w3gh,項目名稱:ghost.js,代碼行數:27,代碼來源:util.ts

示例4:

 handler: () => ({
   hostname: os.hostname(),
   arch: os.arch(),
   platfoirm: os.platform(),
   cpus: os.cpus().length,
   totalmem: humanize.filesize(os.totalmem()),
   networkInterfaces: os.networkInterfaces()
 })
開發者ID:pdxmholmes,項目名稱:alpine-node-hello,代碼行數:8,代碼來源:index.ts

示例5: getIpAddress

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";
}
開發者ID:tcdl,項目名稱:msb,代碼行數:8,代碼來源:serviceDetails.ts

示例6: bindingOutput

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}`);
  }
}
開發者ID:Deathspike,項目名稱:mangarack,代碼行數:8,代碼來源:serve.ts

示例7: function

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; });
}
開發者ID:samsif,項目名稱:angular-cli,代碼行數:56,代碼來源:public-host.ts

示例8: getMac

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)
}
開發者ID:nunsie,項目名稱:prisma,代碼行數:11,代碼來源:StatusChecker.ts

示例9: listInterfaces

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;
}
開發者ID:Kalmac,項目名稱:duniter,代碼行數:12,代碼來源:network.ts

示例10: resolve

 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);
       }
     });
   }
 });
開發者ID:alt-locator,項目名稱:alt-node,代碼行數:12,代碼來源:location.ts


注:本文中的os.networkInterfaces函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。