Node.JS - 处理DNS数据包

时间:2014-04-16 09:05:56

标签: node.js dns network-programming buffer protocols

我想通过UDP服务器事件on.message

读取DNS数据包捕获

如何阅读修正大小数据

分组数据管理就好 我希望按大小分别读取DNS数据包的所有字段。

- 逐位读取nodejs缓冲区对象。 (比特的具体大小)

enter image description here

var s = dgram.createSocket('udp4');
s.bind(53, function() {

});
s.on('message',function(msg,rinfo){
    console.log("Length = "+msg.length);
    console.log(msg.toString('binary'));
    console.log(msg);
    console.log("-----------------------------------------------------------------------");
});

如何实现每个现场数据? 使用on.message param的缓冲区。

感谢。

1 个答案:

答案 0 :(得分:1)

请检查https://www.npmjs.org/package/native-dns-packet

它提供了您所需要的:

Packet.parse(buffer) returns an instance of Packet
Packet.write(buffer, packet) writes the given packet into the buffer, truncating where appropriate