@dnsquery/dns-packet (英语)
一个 抽象编码 dNS 包编码/解码的兼容模块。 升职了 多播广播 作为单独的模块.
这是叉子 联 合 国 dns- 包装 带有打字符类型、 javascript 模块和 不使用 Node.js 原始语。 在浏览器/反应-内生性方面效果良好.
npm install @dnsquery/dns-packet
UDP 用户
import * as dnsPacket from '@dnsquery/dns-packet'
import dgram from 'dgram'
const socket = dgram.createSocket('udp4')
const buf = dnsPacket.encode({
type: 'query',
id: 1,
flags: dnsPacket.RECURSION_DESIRED,
questions: [{
type: 'A',
name: 'google.com'
}]
})
socket.on('message', message => {
console.log(dnsPacket.decode(message)) // prints out a response from google dns
})
socket.send(buf, 0, buf.length, 53, '8.8.8.8')
又见 uDP 实例。 。 。 .
TCP、 TLS、 HTTPS
虽然DNS传统上用于数据克传输,但越来越多地通过TCP传输,用于更大的响应,通常包括DNSSEC响应和加强安全的TLS或HTTPS. 见下文关于如何使用的实例 dns-packet 将 DNS 包包裹在这些协议中 :
API 密码
var buf = packets.encode(packet, [buf], [offset])
将一个DNS包编码成包含UDP有效载荷的缓冲器.
var packet = packets.decode(buf, [offset])
从包含UDP有效载荷的缓冲器中解码出一个DNS包.
var buf = packets.streamEncode(packet, [buf], [offset])
将一个DNS包编码成包含TCP有效载荷的缓冲器.
var packet = packets.streamDecode(buf, [offset])
从含有TCP有效载荷的缓冲器解码出一个DNS包.
var len = packets.encodingLength(packet)
返回编码 DNS 包需要多少字节
软件包
包裹是这样的
{
type: 'query|response',
id: optionalIdNumber,
flags: optionalBitFlags,
questions: [...],
answers: [...],
additionals: [...],
authorities: [...]
}
可用的比特旗是
import {
RECURSION_DESIRED,
RECURSION_AVAILABLE,
TRUNCATED_RESPONSE,
AUTHORITATIVE_ANSWER,
AUTHENTIC_DATA,
CHECKING_DISABLED
} from '@dnsquery/dns-packet'
要用一面多的旗, 或者用它们一起
var flags = packet.RECURSION_DESIRED | packet.RECURSION_AVAILABLE
并检查旗帜是否使用位元
var isRecursive = message.flags & packet.RECURSION_DESIRED
问题是这样的
{
type: 'A', // or SRV, AAAA, etc
class: 'IN', // one of IN, CS, CH, HS, ANY. Default: IN
name: 'google.com' // which record are you looking for
}
而一个答案,额外的,或权威 看起来像这样
{
type: 'A', // or SRV, AAAA, etc
class: 'IN', // one of IN, CS, CH, HS
name: 'google.com', // which name is this record for
ttl: optionalTimeToLiveInSeconds,
(record specific data, see below)
}
支持的记录类型
A
{
data: 'IPv4 address' // fx 127.0.0.1
}
AAAA
{
data: 'IPv6 address' // fx fe80::1
}
CAA
{
flags: 128, // octet
tag: 'issue|issuewild|iodef',
value: 'ca.example.net',
issuerCritical: false
}
CNAME
{
data: 'cname.to.another.record'
}
DNAME
{
data: 'dname.to.another.record'
}
DNSKEY
{
flags: 257, // 16 bits
algorithm: 1, // octet
key: Buffer
}
DS
{
keyTag: 12345,
algorithm: 8,
digestType: 1,
digest: Buffer
}
HINFO
{
data: {
cpu: 'cpu info',
os: 'os info'
}
}
MX
{
preference: 10,
exchange: 'mail.example.net'
}
NS
{
data: nameServer
}
NSEC
{
nextDomain: 'a.domain',
rrtypes: ['A', 'TXT', 'RRSIG']
}
NSEC3
{
algorithm: 1,
flags: 0,
iterations: 2,
salt: Buffer,
nextDomain: Buffer, // Hashed per RFC5155
rrtypes: ['A', 'TXT', 'RRSIG']
}
NULL
{
data: Buffer('any binary data')
}
OPT
EDNS0 数据 选项.
{
type: 'OPT',
name: '.',
udpPayloadSize: 4096,
flags: packet.DNSSEC_OK,
options: [{
// pass in any code/data for generic EDNS0 options
code: 12,
data: Buffer.alloc(31)
}, {
// Several EDNS0 options have enhanced support
code: 'PADDING',
length: 31,
}, {
code: 'CLIENT_SUBNET',
family: 2, // 1 for IPv4, 2 for IPv6
sourcePrefixLength: 64, // used to truncate IP address
scopePrefixLength: 0,
ip: 'fe80::',
}, {
code: 'TCP_KEEPALIVE',
timeout: 150 // increments of 100ms. This means 15s.
}, {
code: 'KEY_TAG',
tags: [1, 2, 3],
}]
}
二. 备选方案 PADDING, (中文(简体) ), CLIENT_SUBNET, (中文(简体) ), TCP_KEEPALIVE 财务报告和审定财务报表 KEY_TAG 加强编码。 见 选项代码.js 用于所有支持的选项代码。 如果 data 属性存在于选项中,优先。 在解码时, data 将永远被定义.
PTR
{
data: 'points.to.another.record'
}
RP
{
mbox: 'admin.example.com',
txt: 'txt.example.com'
}
SSHFP
{
algorithm: 1,
hash: 1,
fingerprint: 'A108C9F834354D5B37AF988141C9294822F5BC00'
}
RRSIG
{
typeCovered: 'A',
algorithm: 8,
labels: 1,
originalTTL: 3600,
expiration: timestamp,
inception: timestamp,
keyTag: 12345,
signersName: 'a.name',
signature: Buffer
}
SOA
{
data:
{
mname: domainName,
rname: mailbox,
serial: zoneSerial,
refresh: refreshInterval,
retry: retryInterval,
expire: expireInterval,
minimum: minimumTTL
}
}
SRV
{
data: {
port: servicePort,
target: serviceHostName,
priority: optionalServicePriority,
weight: optionalServiceWeight
}
}
TXT
{
data: 'text' || Buffer || [ Buffer || 'text' ]
}
在编码时将scalar值转换为数组并被字符串转换为UTF-8编码的缓冲. 解码时,返回值将永远是缓冲数组.
如果你需要另一个唱片类型,打开一个问题 我们将尝试添加它.
许可证
麻省理工学院