Skip to content

Instantly share code, notes, and snippets.

@Marak
Created August 6, 2012 11:43
Show Gist options
  • Save Marak/3273796 to your computer and use it in GitHub Desktop.
Save Marak/3273796 to your computer and use it in GitHub Desktop.
A terrible solution for finding network gateway
//
// Since the code to actually figure this out doesn't exist in node yet
//
// see: https://groups.google.com/forum/?fromgroups#!topic/nodejs-dev/QbcnxS0_yyg
//
var guessGateway = function () {
var network = os.networkInterfaces(),
guess = '10.0.0.1';
Object.keys(network).forEach(function(interfaces){
network[interfaces].forEach(function(interface){
if(!interface.internal && interface.family === "IPv4") {
guess = interface.address.split('.');
guess[guess.length -1] = "1";
guess = guess.join('.');
}
});
})
return guess;
};
@roccomuso
Copy link

What's the best way nowadays to find the gateway's IP Address in Node?

@akrv
Copy link

akrv commented Jan 31, 2017

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment