检索node.js中的networking接口列表(ioctl SIOCGIFCONF)

我是新来的节点,并利用node_pcap攻击一个节点应用程序来捕获数据包数据,并用它做有趣的事情。 捕获数据的input之一是要侦听的networking接口,即“eth0”。

我认为如果能够以编程的方式查找系统上的可用接口并将它们呈现给程序的用户并允许他们select要监听的接口,那将是非常好的。 在C中,我会使用SIOCGIFCONF来使用ioctl (或带有winsock的ioctlsocket)。

我的问题是,目前是否存在一个机制来做到这一点在节点? 我search了很多,还没有到达任何这样的解决scheme。

如果这个function目前不存在,我会假设我可以使用ioctl在C / C ++中编写一个模块绑定来完成这个任务。

感谢您的时间!

从Node.js 0.6.0开始

require('os').getNetworkInterfaces() 

请参阅http://nodejs.org/docs/latest/api/os.html#os.getNetworkInterfaces

如果只想列出接口的名称:

  Object.keys(os.getNetworkInterfaces()) // [ 'lo0', 'en0', 'en3', 'awdl0' ] 

os.networkInterfaces()方法返回的对象只包含已经分配了networking地址的networking接口,但是如果我们想要机器中的所有网卡,我们可以使用这个方法

 var shell = require('shelljs'); var interfaceCard = shell.ls('/sys/class/net'); 

此接口卡具有所有networking接口的列表

输出将是

 [ 'eth0', 'eth1', 'lo', stdout: 'eth0\neth1\nlo\n', stderr: null, code: 0, cat: [Function: bound ], exec: [Function: bound ], grep: [Function: bound ], head: [Function: bound ], sed: [Function: bound ], sort: [Function: bound ], tail: [Function: bound ], to: [Function: bound ], toEnd: [Function: bound ], uniq: [Function: bound ] ] interfaceCard=interfaceCard.stdout.split('\n'); interfaceCard = eth0, eth1, lo 
Interesting Posts