How to use the os.networkInterfaces function in os

To help you get started, we’ve selected a few os examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github evancohen / smart-mirror / main.js View on Github external
// restart it
			startSonus();
		}
	})
}

// Initilize the keyword spotter
if (config && config.speech && !firstRun) {
	startSonus();
}

if (config.remote && config.remote.enabled || firstRun) {
	remote.start()

  // Deturmine the local IP address
	const interfaces = require("os").networkInterfaces()
	let addresses = []
	for (let k in interfaces) {
		for (let k2 in interfaces[k]) {
			let address = interfaces[k][k2]
			if (address.family === "IPv4" && !address.internal) {
				addresses.push(address.address)
			}
		}
	}
	console.log("Remote listening on http://%s:%d", addresses[0], config.remote.port)

	remote.on("command", function (command) {
		mainWindow.webContents.send("final-results", command)
	})

	remote.on("connected", function () {
github NEEOInc / neeo-sdk / lib / discover / index.js View on Github external
function findFirstNeeoBrain(multiInterface) {
  if (!multiInterface) {
    return mdns.findFirstNeeoBrain()
      .then(buildNEEOBrainModel);
  } else {
    const interfaces = os.networkInterfaces();
    const discoveryPromises = Object.keys(interfaces).map((net) =>
      interfaces[net]
        .filter((netInfo) => netInfo.internal === false && netInfo.family === 'IPv4')
        .map((netIf) => mdns.findFirstNeeoBrain(netIf.address)))
      .reduce((result, currentInterface) => result.concat(currentInterface));

    return BluePromise.any(discoveryPromises)
      .then(buildNEEOBrainModel)
      .catch(aggregateError => {
        throw aggregateError[0];
      });
  }
}
github umijs / umi / packages / umi-serve / bin / umi-serve.js View on Github external
function getNetworkAddress() {
  const interfaces = os.networkInterfaces();
  for (const name of Object.keys(interfaces)) {
    for (const interface of interfaces[name]) {
      const { address, family, internal } = interface;
      if (family === 'IPv4' && !internal) {
        return address;
      }
    }
  }
}
github citelab / JAMScript / lib / jamserver / jamlib.js View on Github external
function getMachineAddr() {
    var niaddrs = os.networkInterfaces();
    for (var ni in niaddrs) {
        nielm = niaddrs[ni];
        for (n in nielm) {
            if (nielm[n].family === 'IPv4' && nielm[n].internal === false)
                return nielm[n].address
        }
    }
    return globals.localhost;
}
github palmerabollo / express-ping / lib / health.js View on Github external
name: pjson.name,
        version: pjson.version,
        pid: process.pid,
        title: process.title,
        argv: process.argv,
        versions: process.versions,
        node_env: process.env.NODE_ENV,
        dependencies: pjson.dependencies
      },

      resources: {
        memory: process.memoryUsage(),
        loadavg: os.loadavg(),
        cpu: os.cpus(),
        disk: diskInfo,
        nics: os.networkInterfaces()
      },

      system: {
        arch: process.arch,
        platform: process.platform,
        type: os.type(),
        release: os.release(),
        hostname: os.hostname(),
        uptime: os.uptime(),
        cores: os.cpus().length,
        memory: os.totalmem()
      }
    };

    cb(null, data);
  });
github sprut666666 / com.sprut.homekit / node_modules / bonjour / lib / service.js View on Github external
Service.prototype._records = function () {
  var records = [rrPtr(this), rrSrv(this), rrTxt(this)]

  var self = this
  var interfaces = os.networkInterfaces()
  Object.keys(interfaces).forEach(function (name) {
    interfaces[name].forEach(function (addr) {
      if (addr.internal) return
      if (addr.family === 'IPv4') {
        records.push(rrA(self, addr.address))
      } else {
        records.push(rrAaaa(self, addr.address))
      }
    })
  })

  return records
}
github kristianoye / kmud / src / network / NetUtil.js View on Github external
discovery(callback, refresh) {
        let _ifaces = os.networkInterfaces(),
            finished = 0;

        if (this.networks.length > 0 && refresh !== true) {
            return callback(this.networks);
        }
        this.networks = [];

        process.stdout.write('\nPerforming network scan ');

        let working = setInterval(function () {
            process.stdout.write('.');
        }, 500);

        Object.keys(_ifaces).forEach((ifname) => {
            var alias = 0;
github dpjanes / node-iotdb / helpers / net.js View on Github external
function _scan(filter) { 
    var ifaces = os.networkInterfaces();
    for (var dev in ifaces) {
        var ads = ifaces[dev];
        for (var di in ads) {
            var ad = ads[di];
            var result = filter(ad);
            if (result) {
                return result;
            }
        }
    }

    return null;
}
github Ylianst / MeshCentral / agents / meshcore-OldTerminal.js View on Github external
function sendWakeOnLan(hexMac) {
        var count = 0;
        try {
            var interfaces = require('os').networkInterfaces();
            var magic = 'FFFFFFFFFFFF';
            for (var x = 1; x <= 16; ++x) { magic += hexMac; }
            var magicbin = Buffer.from(magic, 'hex');
            
            for (var adapter in interfaces) {
                if (interfaces.hasOwnProperty(adapter)) {
                    for (var i = 0; i < interfaces[adapter].length; ++i) {
                        var addr = interfaces[adapter][i];
                        if ((addr.family == 'IPv4') && (addr.mac != '00:00:00:00:00:00')) {
                            var socket = require('dgram').createSocket({ type: "udp4" });
                            socket.bind({ address: addr.address });
                            socket.setBroadcast(true);
                            socket.send(magicbin, 7, "255.255.255.255");
                            count++;
                        }
                    }
github PonyCui / XT / service / index.js View on Github external
function address() {
    var os = require('os');
    var IPs = [], hostName;
    hostName = os.hostname();
    for (var key in os.networkInterfaces()) {
        var element = os.networkInterfaces()[key];
        for (var index = 0; index < element.length; index++) {
            var subelement = element[index];
            if (subelement.family === "IPv4") {
                IPs.push(subelement.address);
            }
        }
    }
    IPs.unshift("10.0.2.2")
    return IPs;
}