1

I am trying to create a local server accessible via local network in my electron app. I want to allow incoming access to a specific port.

import server from "./server";
import os from "os";

//TODO determine the local network ip i.e LAN IP
let networkIP = '';

const networkInterfaces = os.networkInterfaces();
//console.log(networkInterfaces);

if (networkInterfaces.hasOwnProperty("lo")) {
  delete networkInterfaces.lo;
}

let noConnectedNetwork = true;

let networkAddresses = [];

Object.keys(networkInterfaces).forEach((key) => {

  let networkInterface = networkInterfaces[key];
  for (let i = 0; i < networkInterface.length; i++) {

    let nInterface = networkInterface[i];

    if (!nInterface.internal && nInterface.family === "IPv4") {
      networkAddresses.push(nInterface.address);
      noConnectedNetwork = false;
    }
  }

});

if (networkAddresses.length > 0) {
  networkIP = networkAddresses[0];
} else {
  //Start a Wi-Fi hotspot if Wi-Fi hardware is available and get the assigned local IP.
}

//Here I want to enable access to port 6795 for the IPs stored in the networkIP

const eServer = {
  start: () => {
    server.start(networkIP);
  }
};

I want the firewall rule to be cross-platform i.e, works on linux(ufw/iptables), mac and windows.

Also, how do I check for wifi hardware and start a hotspot??

Pushkar
  • 760
  • 15
  • 37
  • this is a complex task, you need to fiddle with Windows registry, Linux/Mac config files and more...I doubt you'd find a complete answer here – mihai Oct 22 '18 at 12:24
  • @mihai A bare guideline will be enough for me to work on. – Pushkar Oct 23 '18 at 11:42

0 Answers0