Sunday, March 2, 2014

Node.js: get my IP address

This example list my IP address, coded in Node.js, with module os, run on Raspberry Pi.

list my IP address
list my IP address

var os=require('os');

var networkInterfaces=os.networkInterfaces();

for (var interface in networkInterfaces) {
    
    networkInterfaces[interface].forEach(function(details){
        
        if (details.family=='IPv4') {
            console.log(interface, details.address, 
                        " internal: ", details.internal);  
        }
    });
}

No comments: