0

EDIT: This is because I'm running my application in a docker container. I'm not sure what the best thing to do here is – I could delete the question, but if others are as slow as I am, then I this might lead them to the real question which is here:

How to get the IP address of the docker host from inside a docker container

I'm hoping to get the local IP address of the computer my node application is running on. Using the following:

const nets = require('os').networkInterfaces();
console.log('NETS', nets);

I get this output:

{
lo: [
 {
   address: '127.0.0.1',
   netmask: '255.0.0.0',
   family: 'IPv4',
   mac: '00:00:00:00:00:00',
   internal: true,
   cidr: '127.0.0.1/8'
 }
],
eth0: [
 {
   address: '172.19.0.7',
   netmask: '255.255.0.0',
   family: 'IPv4',
   mac: '02:42:ac:13:00:07',
   internal: false,
   cidr: '172.19.0.7/16'
 }
]

}

I understand that addresses beginning with 172 are local network addresses like those beginning with 192, but if I put that 172 address into a browser nothing happens at all.

If I check my network settings, it says my local address is of the typical 192.168.1.xx sort, and putting that ip in a browser does access my local server.

I'm running this on mac os x.

My end goal is really to get the 192 address if I can, which I thought the networkInterfaces() function would allow me to do. If anyone can help it would be greatly appreciated

Michael

Michael Beeson
  • 2,840
  • 2
  • 17
  • 25

0 Answers0