MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / getLocalIP

Function getLocalIP

utils/scripts/dev.js:56–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54};
55
56function getLocalIP() {
57 const interfaces = os.networkInterfaces();
58 for (const iface of Object.values(interfaces)) {
59 if (!iface) continue;
60 for (const addr of iface) {
61 if (addr.family === "IPv4" && !addr.internal) {
62 // Prefer 192.168.x.x or 10.x.x.x over other private ranges
63 if (
64 addr.address.startsWith("192.168.") ||
65 addr.address.startsWith("10.")
66 ) {
67 return addr.address;
68 }
69 }
70 }
71 }
72 // Fallback: any non-internal IPv4
73 for (const iface of Object.values(interfaces)) {
74 if (!iface) continue;
75 for (const addr of iface) {
76 if (addr.family === "IPv4" && !addr.internal) {
77 return addr.address;
78 }
79 }
80 }
81 return "127.0.0.1";
82}
83
84function getFreePort() {
85 return new Promise((resolve, reject) => {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected