本文整理汇总了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;
}
示例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')
})
示例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;
}
示例4:
handler: () => ({
hostname: os.hostname(),
arch: os.arch(),
platfoirm: os.platform(),
cpus: os.cpus().length,
totalmem: humanize.filesize(os.totalmem()),
networkInterfaces: os.networkInterfaces()
})
示例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";
}
示例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}`);
}
}
示例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; });
}
示例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)
}
示例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;
}
示例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);
}
});
}
});