libpcap的node绑定:node_pcap

jopen 10年前

这个项目为node提供了一个组libpcap绑定,包含一些实用的库来解码,打印和分析数据包。libpcap是tcpdumpwireshark程序使用的网络抓包工具。经测试支持 OSX和Linux。

var pcap = require('pcap'),      tcp_tracker = new pcap.TCP_tracker(),      pcap_session = pcap.createSession(interface, "ip proto \\tcp");     tcp_tracker.on('start', function (session) {      console.log("Start of TCP session between " + session.src_name + " and " + session.dst_name);  });     tcp_tracker.on('end', function (session) {      console.log("End of TCP session between " + session.src_name + " and " + session.dst_name);  });     pcap_session.on('packet', function (raw_packet) {      var packet = pcap.decode.packet(raw_packet);      tcp_tracker.track_packet(packet);  });

项目主页:http://www.open-open.com/lib/view/home/1408006807770