0

I need to get local IP of my computer in react js app. Can anyone please suggest a good way to do it?

Debarth
  • 160
  • 1
  • 12
  • 3
    Why do you need to do that? You've tagged electron, so maybe an approach that works with Electron is what you need, e.g. https://stackoverflow.com/questions/10750303/how-can-i-get-the-local-ip-address-in-node-js – AKX Jan 14 '22 at 14:10
  • 1
    Local LAN IP? Or public internet-facing IP, if any? IPv4? IPv6? What if your device has more than one active network interface, should it return all the assigned IPs? And yeah...why does your application need to know? – ADyson Jan 14 '22 at 14:12

1 Answers1

1

Any IP address of your machine you can find by using the os module - and that's native to Node.js:

const os = require('os');

const networkInterfaces = os.networkInterfaces();
const ip = networkInterfaces['eth0'][0]['address']

console.log(networkInterfaces);
Mile Mijatović
  • 2,535
  • 1
  • 22
  • 36