How to get public ip and local ip address in Raspberry pi 3 using nodejs
Posted By : Chandan Kumar Singh | 28-Dec-2016
In this blog we will fetch Raspberry pi internal ip address and public ip address if it is connected to the internet.
For getting public ip address you can use external-ip library.
Example
require('external-ip')()(function(err, ip) { if (!err) { console.log(ip); } else { console.log(err); } });
To get internal ip address.
var interfaces = require('os').networkInterfaces(); var addresses = []; for (var k in interfaces) { for (var k2 in interfaces[k]) { var address = interfaces[k][k2]; if (address.family === 'IPv4' && address.address !== '127.0.0.1' && !address.internal){ addresses.push(address.address); } } } console.log(addresses);
Now you can further process the ips according to your requirement.
Thanks
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Chandan Kumar Singh
Chandan is a bright Web Developer with expertise in Java and Spring framework and ORM tools Hibernate. He loves technologies like Blockchain and IoT.