getWifiIPv4.js 387 B

123456789101112131415
  1. import { networkInterfaces } from "node:os";
  2. export default () => {
  3. const interfaces = networkInterfaces();
  4. for (const name of Object.keys(interfaces)) {
  5. if (!name.startsWith('wlan') && !name.startsWith('wlp')) continue
  6. for (const net of interfaces[name]) {
  7. if (net.family !== "IPv4" || net.internal) continue
  8. return net.address;
  9. }
  10. }
  11. }