proxyman-windows-linux
proxyman-windows-linux copied to clipboard
[BUG] Proxyman sometimes can't detect the IPv4 from PC. It shows a default value 127.0.0.1
Description
There are at least 2 users, who reported this bug.
It shows 127.0.0.1
(default value) in the Android Setup, and the status bar.
Steps to Reproduce
- Not sure hot to reproduce it, but it's failed to get the current IPv4
Current Behavior
- Can't get the current IPv4
Expected Behavior
- [ ] Double check the func, to see why Proxyman can't fetch any IPv4
- [ ] Find a better npm package (high download, reliable, ... ) (maybe we can fall back to current library if the new one doesn't work) -> Find in this docs: https://www.electronjs.org/docs/latest/api/session to see if we have any native API to get the IPv4
Maybe we can leverage the os
from NodeJS.
const os = require('os');
function getIPv4Address() {
const networkInterfaces = os.networkInterfaces();
for (const interfaceDetail of Object.values(networkInterfaces)) {
// `interfaceDetail` might be undefined if no network is attached to the interface
if (!interfaceDetail) {
continue;
}
for (const detail of interfaceDetail) {
// Look for an IPv4 address that is not an internal (localhost) address
if (detail.family === 'IPv4' && !detail.internal) {
return detail.address;
}
}
}
// Return undefined or a fallback address if no external IPv4 address was found
return '127.0.0.1';
}
console.log(getIPv4Address());