forked from LittleChest/dns-packet
* Add encoder for stream transports (TCP/TLS). Fixes #16. * Add README text and return null on short buffer.
31 lines
606 B
JavaScript
31 lines
606 B
JavaScript
'use strict'
|
|
|
|
const packet = require('./')
|
|
const net = require('net')
|
|
|
|
const buf = packet.streamEncode({
|
|
type: 'query',
|
|
id: 0xdead,
|
|
flags: packet.RECURSION_DESIRED,
|
|
questions: [{
|
|
type: 'A',
|
|
name: 'google.com'
|
|
}]
|
|
})
|
|
|
|
const client = new net.Socket()
|
|
client.connect(53, '8.8.8.8', function () {
|
|
console.log('Connected')
|
|
client.write(buf)
|
|
})
|
|
|
|
client.on('data', function (data) {
|
|
console.log('Received response')
|
|
console.log(packet.streamDecode(data))
|
|
client.destroy() // kill client after server's response
|
|
})
|
|
|
|
client.on('close', function () {
|
|
console.log('Connection closed')
|
|
})
|