Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
19
rated 0 times [  23] [ 4]  / answers: 1 / hits: 15706  / 13 Years ago, sat, october 15, 2011, 12:00:00

I'm new to node and am hacking together a node application utilizing node_pcap to capture packet data and do interesting things with it. One of the inputs to capturing data is the network interface to listen on, i.e. eth0.



I thought it would be really great if I could programmatically look up the available interfaces on the system and present them to the user of the program and allow them to pick which interface to listen on. In C, I would use ioctl (or ioctlsocket with winsock) using SIOCGIFCONF.



My question is, does there currently exist a mechanism to do this in node? I've searched quite a bit and haven't arrived to any such solution.



If this functionality does not currently exist, I would assume I'd be able to write a Module binding in C/C++ using ioctl to accomplish this.



Thank you for your time!


More From » node.js

 Answers
84

Update valid as of Node 13.7.0



This has been renamed since this answer was submitted. It is now just networkInterfaces() like this:



require('os').networkInterfaces()


Or probably preferably like this:



import { networkInterfaces } from 'os';

const interfaces = networkInterfaces();


New docs url: https://nodejs.org/docs/latest/api/os.html#os_os_networkinterfaces



Original answer



As of Node.js 0.6.0 you have



require('os').getNetworkInterfaces()


See http://nodejs.org/docs/latest/api/os.html#os.getNetworkInterfaces


[#89599] Thursday, October 13, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
calicinthias

Total Points: 447
Total Questions: 101
Total Answers: 118

Location: Botswana
Member since Sat, Dec 31, 2022
1 Year ago
calicinthias questions
Sun, Jan 2, 22, 00:00, 2 Years ago
Wed, Jan 13, 21, 00:00, 3 Years ago
Mon, Aug 10, 20, 00:00, 4 Years ago
;