Merge branch 'v1'
This commit is contained in:
commit
c0338ef3fa
49
README.md
49
README.md
|
@ -89,6 +89,9 @@ npm test
|
|||
Usage
|
||||
-----
|
||||
|
||||
* CLI
|
||||
* API
|
||||
|
||||
**CLI**
|
||||
|
||||
You can work directly from `node_modules/dns-suite`:
|
||||
|
@ -97,19 +100,6 @@ You can work directly from `node_modules/dns-suite`:
|
|||
pushd node_modules/dns-suite/
|
||||
```
|
||||
|
||||
Capture mDNS broadcast packets
|
||||
|
||||
```bash
|
||||
# example
|
||||
# node bin/mdns-capture.js <file-prefix>
|
||||
node bin/mdns-capture.js mdns-test
|
||||
```
|
||||
|
||||
```bash
|
||||
# in another terminal
|
||||
dig @224.0.0.251 -p 5353 -t PTR _services._dns-sd._udp.local
|
||||
```
|
||||
|
||||
Parsing a saved packet
|
||||
|
||||
```bash
|
||||
|
@ -124,28 +114,49 @@ should be.
|
|||
|
||||
**Library**
|
||||
|
||||
* `packet = dnsjs.unpack(arrayBuffer)`
|
||||
* `packet = dnsjs.unpackRdatas(arrayBuffer, packet)`
|
||||
* `packet.answers[0].data = dnsjs.unpackRdatas(arrayBuffer, packet, packet.answers[0])`
|
||||
* `DNSPacket.parse(nodeOrArrayBuffer)` returns json (as shown above)
|
||||
* `DNSPacket.pack(packet)` returns ArrayBuffer (browser and node)
|
||||
* `DNSPacket.write(packet)` returns NodeBuffer (node only)
|
||||
|
||||
node.js:
|
||||
```js
|
||||
var nodeBuffer = fs.readFileSync('./samples/a-0.mdns.bin');
|
||||
var arrayBuffer = nodeBuffer.buffer;
|
||||
|
||||
var dnsjs = require('dns-suite');
|
||||
var packet = dnsjs.unpack(arrayBuffer);
|
||||
var DNSPacket = require('dns-suite').DNSPacket;
|
||||
var packet = DNSPacket.parse(arrayBuffer);
|
||||
var ab = DNSPacket.pack(packet);
|
||||
|
||||
console.log(packet);
|
||||
console.log(new Uint8Array(ab));
|
||||
```
|
||||
|
||||
Browser:
|
||||
```js
|
||||
var arrayBuffer = new Uint8Array.from([ /* bytes */ ]).buffer;
|
||||
|
||||
var packet = pdns.unpack(arrayBuffer);
|
||||
var packet = DNSPacket.parse(arrayBuffer);
|
||||
var ab = DNSPacket.pack(packet);
|
||||
|
||||
console.log(packet);
|
||||
console.log(new Uint8Array(ab));
|
||||
```
|
||||
|
||||
|
||||
Capturing Packets
|
||||
-----
|
||||
|
||||
We have a command line tool for that! See [dig.js](https://git.daplie.com/Daplie/dig.js).
|
||||
|
||||
```
|
||||
# Install
|
||||
npm install -g 'git+https://git@git.daplie.com/Daplie/dig.js.git'
|
||||
|
||||
# Use with DNS
|
||||
dig.js A daplie.com --output .
|
||||
|
||||
# Use with mDNS
|
||||
dig.js --mdns PTR _services._dns-sd._udp.local --output .
|
||||
```
|
||||
|
||||
Contributing and Development
|
||||
|
|
6
dns.js
6
dns.js
|
@ -8,7 +8,11 @@ var Packer = (exports.DNS_PACKER || require('./dns.packer.js').DNS_PACKER);
|
|||
exports.DNSPacket = {
|
||||
parse: function (nb) {
|
||||
// backwards compat with node buffer
|
||||
var ab = nb.buffer || nb;
|
||||
var ab = nb;
|
||||
if (nb.buffer) {
|
||||
// TODO pass byteOffsets to unpacker
|
||||
ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
|
||||
}
|
||||
var packet = Parser.unpack(ab);
|
||||
|
||||
function tryParseRdata(record) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "dns-suite",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"description": "testing dns",
|
||||
"main": "dns.js",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue