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

标签 node.js ip gateway

现在在 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/

相关文章:

angularjs - URI 中包含斜杠字符 '/' 的标识符

node.js - Sequelize : findOne auto commits during transaction (using clsHooked)

amazon-ec2 - Amazon EBS EC2 实例 IP 在重启时更改

python - 如何循环遍历用户在 python 中输入的 IP 地址

java - <int :gateway xml tag in java DSL in spring - integration? 的模拟是什么

c# - C# 中的 SMS 库

node.js - 在多个浏览器上运行测试(顺序)

javascript - 在 Javascript 中扩展对象数组

c - 使用目标MAC的ARP数据包

gateway - 编写USSD客户端或USSD开源/待购买客户端