当前位置: 首页>>代码示例>>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;未经允许,请勿转载。