现在在 Node.js 中查找默认网关 IP 地址的最佳方法是什么?os.networkInterfaces()
不提供此信息。
唯一想到的想法是解析子进程的标准输出 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
最佳答案
使用网络包: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.'
})
关于node.js - 在 Node.js 中查找默认网关 IP 的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41695391/