我正在尝试在我的电子应用程序中创建可通过本地网络访问的本地服务器。 我想允许传入访问特定端口。
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);
}
};
我希望防火墙规则是跨平台的,即可以在linux(ufw / iptables),mac和Windows上运行。
另外,如何检查wifi硬件并启动热点?