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
====
@ -69,7 +153,7 @@ which is located in the node.js buffer module. The API is [here](https://nodejs.
However, the error we are working with will most likely be dealt with by parsing through the binary
and putting it in a format that is acceptable to a custom buffer, since the current buffer.js does doesn't seem to do the trick.
Using
Using
```javascript
function pad(str, len, ch) {
@ -170,7 +254,7 @@ function parseFlags(val, packet) {
}
```
One effective way to check is to create a dns packet, pass it to
One effective way to check is to create a dns packet, pass it to
a custom packer and parser function and compare the input and output:
```javascript
@ -257,6 +341,6 @@ socket.on('message', function (message, rinfo) {
DNS sec: security
DNS sec: security
puts a signature on a DNS packet and imprints a signature so that the sender of
the packet is confirmed

View File

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