This commit is contained in:
AJ ONeal 2017-01-21 15:07:10 -07:00
parent 4ecb1b679c
commit f3a3c477a5
2 changed files with 92 additions and 6 deletions

View File

@ -1,3 +1,87 @@
dns-lint
========
Fast, lightweight, **pure JavaScript** (ES5.1) implementation for DNS / mDNS.
Works great in **Web Browsers** and in node.js!
Details error checking makes it great for
* capture
* packing (JSON to DNS)
* parsing (DNS to JSON)
* linting (finding errors in packets)
* debugging
**No external dependencies** for modern browsers. Uses `DataView`, `Uint8Array`, `Uint16Array`, and `ArrayBuffer`
Similar API to `dns.js` and `native-dns-packet`.
Install
-------
```
npm install git+https://git@git.daplie.com:Daplie/dns-lint
```
Usage
-----
**CLI**
You can work directly from `node_modules/dns-lint`:
```
pushd node_modules/dns-lint/
```
Capture mDNS broadcast packets
```
# example
# node bin/mdns-capture.js <file-prefix>
node bin/mdns-capture.js mdns-test
```
```
# in another terminal
dig @224.0.0.251 -p 5353 -t PTR _services._dns-sd._udp.local
```
Parsing a saved packet
```
# example
# node bin/dns-parse.js </path/to/packet.dns.bin>
node bin/dns-parse.js samples/a-0.mdns.bin
```
**Library**
* `packet = dnsjs.unpack(arrayBuffer)`
* `packet = dnsjs.unpackRdatas(arrayBuffer, packet)`
* `packet.answers[0].data = dnsjs.unpackRdatas(arrayBuffer, packet, packet.answers[0])`
node.js:
```
var nodeBuffer = fs.readFileSync('./samples/a-0.mdns.bin');
var arrayBuffer = nodeBuffer.buffer;
var dnsjs = require('dns-lint');
var packet = dnsjs.unpack(arrayBuffer);
console.log(packet);
```
Browser:
```
var arrayBuffer = new Uint8Array.from([ /* bytes */ ]).buffer;
var packet = pdns.unpack(arrayBuffer);
console.log(packet);
```
mDNS Documentation mDNS Documentation
==== ====

View File

@ -25,11 +25,13 @@ handlers.onError = function (err) {
}; };
handlers.onMessage = function (buffer) { handlers.onMessage = function (buffer) {
var path = require('path'); var path = require('path');
var name = type + '-' + count + '.mdns.bin'; var filename = type + '-' + count + '.mdns.bin';
var fullpath = path.join('samples', filename);
count += 1; count += 1;
fs.writeFileAsync(path.join('samples', name), buffer).then(function () { fs.writeFileAsync(fullpath, buffer).then(function () {
console.log('wrote ' + buffer.length + ' bytes to ' + name); console.log('wrote ' + buffer.length + ' bytes to ' + fullpath);
}); });
}; };
handlers.onListening = function () { handlers.onListening = function () {