Created
August 6, 2012 11:43
-
-
Save Marak/3273796 to your computer and use it in GitHub Desktop.
A terrible solution for finding network gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1