kiro-mobile-bridge 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/network.js +32 -6
package/package.json
CHANGED
package/src/utils/network.js
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { networkInterfaces } from 'os';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Check if interface is IPv4
|
|
8
|
+
* Handles both string ('IPv4') and number (4) family values
|
|
9
|
+
* @param {object} iface - Network interface object
|
|
10
|
+
* @returns {boolean}
|
|
11
|
+
*/
|
|
12
|
+
function isIPv4(iface) {
|
|
13
|
+
return iface.family === 'IPv4' || iface.family === 4;
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
/**
|
|
7
17
|
* Get local IP address for LAN access
|
|
8
18
|
* Returns the first non-internal IPv4 address found.
|
|
@@ -15,25 +25,41 @@ import { networkInterfaces } from 'os';
|
|
|
15
25
|
export function getLocalIP() {
|
|
16
26
|
const interfaces = networkInterfaces();
|
|
17
27
|
|
|
18
|
-
// Prioritize common interface names
|
|
19
|
-
const priorityInterfaces = ['
|
|
28
|
+
// Prioritize common interface names (Linux, macOS, Windows)
|
|
29
|
+
const priorityInterfaces = ['Ethernet', 'Wi-Fi', 'eth0', 'en0', 'wlan0'];
|
|
20
30
|
|
|
21
31
|
// First, try priority interfaces
|
|
22
32
|
for (const name of priorityInterfaces) {
|
|
23
33
|
const ifaces = interfaces[name];
|
|
24
34
|
if (ifaces) {
|
|
25
35
|
for (const iface of ifaces) {
|
|
26
|
-
if (iface
|
|
36
|
+
if (isIPv4(iface) && !iface.internal) {
|
|
27
37
|
return iface.address;
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
41
|
}
|
|
32
42
|
|
|
33
|
-
// Fallback: return first non-internal IPv4
|
|
43
|
+
// Fallback: return first non-internal IPv4 (skip virtual/WSL interfaces)
|
|
44
|
+
for (const name of Object.keys(interfaces)) {
|
|
45
|
+
// Skip virtual interfaces (WSL, Docker, VPN, etc.)
|
|
46
|
+
if (name.toLowerCase().includes('vethernet') ||
|
|
47
|
+
name.toLowerCase().includes('docker') ||
|
|
48
|
+
name.toLowerCase().includes('vmware') ||
|
|
49
|
+
name.toLowerCase().includes('virtualbox')) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
for (const iface of interfaces[name]) {
|
|
53
|
+
if (isIPv4(iface) && !iface.internal) {
|
|
54
|
+
return iface.address;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Last resort: any non-internal IPv4
|
|
34
60
|
for (const name of Object.keys(interfaces)) {
|
|
35
61
|
for (const iface of interfaces[name]) {
|
|
36
|
-
if (iface
|
|
62
|
+
if (isIPv4(iface) && !iface.internal) {
|
|
37
63
|
return iface.address;
|
|
38
64
|
}
|
|
39
65
|
}
|
|
@@ -54,7 +80,7 @@ export function getAllLocalIPs() {
|
|
|
54
80
|
|
|
55
81
|
for (const name of Object.keys(interfaces)) {
|
|
56
82
|
for (const iface of interfaces[name]) {
|
|
57
|
-
if (iface
|
|
83
|
+
if (isIPv4(iface) && !iface.internal) {
|
|
58
84
|
results.push({ name, address: iface.address });
|
|
59
85
|
}
|
|
60
86
|
}
|