在Node.js中查找默认网关IP的最佳方式是什么?

现在在Node.js中find默认网关IP地址的最佳方式是什么?

os.networkInterfaces()不提供这个信息。

想到的唯一想法是parsing一个subprocessroute -n标准输出 route -n

 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.2 0.0.0.0 UG 100 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 

使用networking包: https : //www.npmjs.com/package/network

;)

 network.get_gateway_ip(function(err, ip) { console.log(err || ip); // err may be 'No active network interface found.' }) 
Interesting Posts