or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

dns-client.mddns-core.mddns-records.mddns-resolvers.mddns-server.mddns-utils.mdindex.md

dns-records.mddocs/

0

# DNS Resource Records

1

2

Comprehensive support for DNS resource record types including address records, mail exchange, name servers, text records, and DNSSEC extensions. All record types are implemented as resource data (RD) classes that can be used with the RR container.

3

4

## Base Resource Data Class

5

6

```python { .api }

7

class RD:

8

"""

9

Base class for all DNS resource data types.

10

11

Args:

12

data (bytes, optional): Raw resource data

13

"""

14

def __init__(self, data=b""): ...

15

16

def pack(self, buffer):

17

"""

18

Pack resource data to wire format.

19

20

Args:

21

buffer (Buffer): Output buffer

22

"""

23

24

@classmethod

25

def parse(cls, buffer, length):

26

"""

27

Parse resource data from wire format buffer.

28

29

Args:

30

buffer (Buffer): Input buffer

31

length (int): Data length

32

33

Returns:

34

RD: Parsed resource data object

35

"""

36

37

@classmethod

38

def fromZone(cls, rd, origin=None):

39

"""

40

Parse resource data from zone file format.

41

42

Args:

43

rd (str): Zone file format string

44

origin (DNSLabel, optional): Origin domain

45

46

Returns:

47

RD: Parsed resource data object

48

"""

49

50

def toZone(self):

51

"""

52

Convert resource data to zone file format.

53

54

Returns:

55

str: Zone file format string

56

"""

57

```

58

59

## Capabilities

60

61

### Address Records

62

63

IPv4 and IPv6 address resource records for domain name to IP address mapping.

64

65

```python { .api }

66

class A:

67

"""

68

IPv4 address resource record.

69

70

Args:

71

data (str): IPv4 address (e.g., "192.0.2.1")

72

"""

73

def __init__(self, data): ...

74

75

def pack(self, buffer):

76

"""Pack A record to wire format."""

77

78

@classmethod

79

def parse(cls, buffer, length):

80

"""Parse A record from wire format buffer."""

81

82

@classmethod

83

def fromZone(cls, rd, origin=None):

84

"""Parse A record from zone file format."""

85

86

def toZone(self):

87

"""Convert A record to zone file format."""

88

89

class AAAA:

90

"""

91

IPv6 address resource record.

92

93

Args:

94

data (str): IPv6 address (e.g., "2001:db8::1")

95

"""

96

def __init__(self, data): ...

97

98

def pack(self, buffer):

99

"""Pack AAAA record to wire format."""

100

101

@classmethod

102

def parse(cls, buffer, length):

103

"""Parse AAAA record from wire format buffer."""

104

105

@classmethod

106

def fromZone(cls, rd, origin=None):

107

"""Parse AAAA record from zone file format."""

108

109

def toZone(self):

110

"""Convert AAAA record to zone file format."""

111

```

112

113

### Name Records

114

115

Records for aliasing and delegation including canonical names and pointer records.

116

117

```python { .api }

118

class CNAME:

119

"""

120

Canonical name resource record for domain aliasing.

121

122

Args:

123

label (str or DNSLabel): Canonical domain name

124

"""

125

def __init__(self, label): ...

126

127

class PTR:

128

"""

129

Pointer resource record for reverse DNS lookups.

130

Inherits from CNAME.

131

132

Args:

133

label (str or DNSLabel): Target domain name

134

"""

135

def __init__(self, label): ...

136

137

class NS:

138

"""

139

Name server resource record.

140

Inherits from CNAME.

141

142

Args:

143

label (str or DNSLabel): Name server domain name

144

"""

145

def __init__(self, label): ...

146

147

class DNAME:

148

"""

149

Delegation name resource record.

150

Inherits from CNAME.

151

152

Args:

153

label (str or DNSLabel): Delegation target domain name

154

"""

155

def __init__(self, label): ...

156

```

157

158

### Mail Exchange Records

159

160

Records for email routing and mail server specification.

161

162

```python { .api }

163

class MX:

164

"""

165

Mail exchange resource record.

166

167

Args:

168

preference (int): Priority value (lower values have higher priority)

169

mx (str or DNSLabel): Mail server domain name

170

"""

171

def __init__(self, preference, mx): ...

172

```

173

174

### Text Records

175

176

Records for storing arbitrary text data including SPF, DKIM, and other metadata.

177

178

```python { .api }

179

class TXT:

180

"""

181

Text resource record for arbitrary text data.

182

183

Args:

184

data (str or list[str]): Text data (list for multiple strings)

185

"""

186

def __init__(self, data): ...

187

```

188

189

### Start of Authority Records

190

191

SOA records defining authoritative information about DNS zones.

192

193

```python { .api }

194

class SOA:

195

"""

196

Start of authority resource record.

197

198

Args:

199

mname (str or DNSLabel): Primary name server

200

rname (str or DNSLabel): Responsible person email (@ replaced with .)

201

times (tuple or list): (serial, refresh, retry, expire, minimum) values

202

"""

203

def __init__(self, mname, rname, times): ...

204

```

205

206

### Service Records

207

208

Records for service location and priority specification.

209

210

```python { .api }

211

class SRV:

212

"""

213

Service resource record for service location.

214

215

Args:

216

priority (int): Priority value (lower values have higher priority)

217

weight (int): Weight for load balancing among same priority

218

port (int): Service port number

219

target (str or DNSLabel): Target server domain name

220

"""

221

def __init__(self, priority, weight, port, target): ...

222

223

class NAPTR:

224

"""

225

Naming authority pointer resource record.

226

227

Args:

228

order (int): Processing order

229

preference (int): Preference value

230

flags (str): Application flags

231

service (str): Service parameters

232

regexp (str): Regular expression for rewriting

233

replacement (str or DNSLabel): Replacement domain name

234

"""

235

def __init__(self, order, preference, flags, service, regexp, replacement): ...

236

```

237

238

### DNSSEC Records

239

240

Records for DNS Security Extensions providing authentication and integrity.

241

242

```python { .api }

243

class DS:

244

"""

245

Delegation signer resource record for DNSSEC.

246

247

Args:

248

key_tag (int): Key tag value

249

algorithm (int): Algorithm identifier

250

digest_type (int): Digest algorithm identifier

251

digest (str or bytes): Cryptographic digest

252

"""

253

def __init__(self, key_tag, algorithm, digest_type, digest): ...

254

255

class DNSKEY:

256

"""

257

DNS key resource record for DNSSEC.

258

259

Args:

260

flags (int): Key flags (256=ZSK, 257=KSK)

261

protocol (int): Protocol field (always 3)

262

algorithm (int): Algorithm identifier

263

key (str or bytes): Public key data

264

"""

265

def __init__(self, flags, protocol, algorithm, key): ...

266

267

class RRSIG:

268

"""

269

Resource record signature for DNSSEC.

270

271

Args:

272

covered (int): Type of RR covered by signature

273

algorithm (int): Algorithm identifier

274

labels (int): Number of labels in original owner name

275

orig_ttl (int): Original TTL value

276

sig_exp (int): Signature expiration time

277

sig_inc (int): Signature inception time

278

key_tag (int): Key tag value

279

name (str or DNSLabel): Signer name

280

sig (str or bytes): Signature data

281

"""

282

def __init__(self, covered, algorithm, labels, orig_ttl, sig_exp, sig_inc, key_tag, name, sig): ...

283

284

class NSEC:

285

"""

286

Next secure resource record for DNSSEC authenticated denial.

287

288

Args:

289

label (str or DNSLabel): Next owner name

290

type_bitmap (bytes or list[int]): Type bitmap of existing records

291

"""

292

def __init__(self, label, type_bitmap): ...

293

```

294

295

### Certificate and Security Records

296

297

Records for certificate authority authorization and security information.

298

299

```python { .api }

300

class CAA:

301

"""

302

Certificate authority authorization resource record.

303

304

Args:

305

flags (int): Flags field (0=non-critical, 128=critical)

306

tag (str): Property tag ("issue", "issuewild", "iodef")

307

value (str): Property value

308

"""

309

def __init__(self, flags, tag, value): ...

310

311

class SSHFP:

312

"""

313

SSH key fingerprint resource record.

314

315

Args:

316

algorithm (int): Algorithm identifier (1=RSA, 2=DSS, 3=ECDSA, 4=Ed25519)

317

fp_type (int): Fingerprint type (1=SHA-1, 2=SHA-256)

318

fingerprint (str or bytes): Key fingerprint

319

"""

320

def __init__(self, algorithm, fp_type, fingerprint): ...

321

322

class TLSA:

323

"""

324

Transport layer security authentication resource record.

325

326

Args:

327

usage (int): Certificate usage (0-3)

328

selector (int): Selector field (0=full cert, 1=public key)

329

mtype (int): Matching type (0=exact, 1=SHA-256, 2=SHA-512)

330

cert (str or bytes): Certificate association data

331

"""

332

def __init__(self, usage, selector, mtype, cert): ...

333

```

334

335

### Service Binding Records

336

337

Records for modern service binding and HTTPS service parameters.

338

339

```python { .api }

340

class HTTPS:

341

"""

342

HTTPS service binding resource record.

343

344

Args:

345

priority (int): Priority value (0=alias mode, >0=service mode)

346

target (str or DNSLabel): Target domain name

347

params (dict, optional): Service parameters

348

"""

349

def __init__(self, priority, target, params=None): ...

350

```

351

352

### Location and Contact Records

353

354

Records for geographical location and responsible person information.

355

356

```python { .api }

357

class LOC:

358

"""

359

Location resource record for geographical information.

360

361

Args:

362

lat (float): Latitude in degrees

363

lon (float): Longitude in degrees

364

alt (float): Altitude in meters

365

size (float): Size of location in meters

366

hp (float): Horizontal precision in meters

367

vp (float): Vertical precision in meters

368

"""

369

def __init__(self, lat, lon, alt, size=1, hp=10000, vp=10): ...

370

371

class RP:

372

"""

373

Responsible person resource record.

374

375

Args:

376

mbox (str or DNSLabel): Mailbox domain name (@ replaced with .)

377

txt (str or DNSLabel): TXT record with additional information

378

"""

379

def __init__(self, mbox, txt): ...

380

```

381

382

## Type Constants and Mappings

383

384

```python { .api }

385

# DNS record type mappings

386

QTYPE = Bimap(

387

A=1, NS=2, MD=3, MF=4, CNAME=5, SOA=6, MB=7, MG=8, MR=9, NULL=10,

388

WKS=11, PTR=12, HINFO=13, MINFO=14, MX=15, TXT=16, RP=17, AFSDB=18,

389

X25=19, ISDN=20, RT=21, NSAP=22, NSAP_PTR=23, SIG=24, KEY=25,

390

PX=26, GPOS=27, AAAA=28, LOC=29, NXT=30, EID=31, NIMLOC=32,

391

SRV=33, ATMA=34, NAPTR=35, KX=36, CERT=37, A6=38, DNAME=39,

392

SINK=40, OPT=41, APL=42, DS=43, SSHFP=44, IPSECKEY=45, RRSIG=46,

393

NSEC=47, DNSKEY=48, DHCID=49, NSEC3=50, NSEC3PARAM=51, TLSA=52,

394

SMIMEA=53, HIP=55, NINFO=56, RKEY=57, TALINK=58, CDS=59, CDNSKEY=60,

395

OPENPGPKEY=61, CSYNC=62, ZONEMD=63, SVCB=64, HTTPS=65, SPF=99,

396

UINFO=100, UID=101, GID=102, UNSPEC=103, NID=104, L32=105, L64=106,

397

LP=107, EUI48=108, EUI64=109, TKEY=249, TSIG=250, IXFR=251, AXFR=252,

398

MAILB=253, MAILA=254, ANY=255, URI=256, CAA=257, AVC=258, DOA=259,

399

AMTRELAY=260, TA=32768, DLV=32769

400

)

401

402

# Resource record class to type mapping

403

RDMAP = {

404

'A': A, 'AAAA': AAAA, 'CNAME': CNAME, 'PTR': PTR, 'NS': NS, 'DNAME': DNAME,

405

'MX': MX, 'TXT': TXT, 'SOA': SOA, 'SRV': SRV, 'NAPTR': NAPTR,

406

'DS': DS, 'DNSKEY': DNSKEY, 'RRSIG': RRSIG, 'NSEC': NSEC,

407

'CAA': CAA, 'SSHFP': SSHFP, 'TLSA': TLSA, 'HTTPS': HTTPS,

408

'LOC': LOC, 'RP': RP

409

}

410

```

411

412

## Usage Examples

413

414

### Creating Address Records

415

416

```python

417

from dnslib import *

418

419

# IPv4 address record

420

a_record = RR("example.com", QTYPE.A, rdata=A("192.0.2.1"), ttl=300)

421

print(a_record)

422

423

# IPv6 address record

424

aaaa_record = RR("example.com", QTYPE.AAAA, rdata=AAAA("2001:db8::1"), ttl=300)

425

print(aaaa_record)

426

427

# From zone file format

428

records = RR.fromZone("""

429

example.com. 300 IN A 192.0.2.1

430

example.com. 300 IN AAAA 2001:db8::1

431

""")

432

for rr in records:

433

print(rr)

434

```

435

436

### Creating Mail Exchange Records

437

438

```python

439

from dnslib import *

440

441

# MX record with priority

442

mx_record = RR("example.com", QTYPE.MX, rdata=MX(10, "mail.example.com"), ttl=300)

443

print(mx_record)

444

445

# Multiple MX records with different priorities

446

mx_records = RR.fromZone("""

447

example.com. 300 IN MX 10 mail1.example.com.

448

example.com. 300 IN MX 20 mail2.example.com.

449

example.com. 300 IN MX 30 mail3.example.com.

450

""")

451

for rr in mx_records:

452

print(rr)

453

```

454

455

### Creating Text Records

456

457

```python

458

from dnslib import *

459

460

# Simple TXT record

461

txt_record = RR("example.com", QTYPE.TXT, rdata=TXT("v=spf1 include:_spf.example.com ~all"), ttl=300)

462

print(txt_record)

463

464

# TXT record with multiple strings

465

txt_multi = RR("example.com", QTYPE.TXT, rdata=TXT(["First string", "Second string"]), ttl=300)

466

print(txt_multi)

467

468

# From zone file format

469

txt_records = RR.fromZone("""

470

example.com. 300 IN TXT "v=spf1 include:_spf.example.com ~all"

471

_dmarc.example.com. 300 IN TXT "v=DMARC1; p=reject; rua=mailto:dmarc@example.com"

472

""")

473

for rr in txt_records:

474

print(rr)

475

```

476

477

### Creating Service Records

478

479

```python

480

from dnslib import *

481

482

# SRV record for service location

483

srv_record = RR("_http._tcp.example.com", QTYPE.SRV,

484

rdata=SRV(10, 60, 80, "www.example.com"), ttl=300)

485

print(srv_record)

486

487

# Multiple SRV records for load balancing

488

srv_records = RR.fromZone("""

489

_http._tcp.example.com. 300 IN SRV 10 60 80 www1.example.com.

490

_http._tcp.example.com. 300 IN SRV 10 40 80 www2.example.com.

491

_http._tcp.example.com. 300 IN SRV 20 0 80 backup.example.com.

492

""")

493

for rr in srv_records:

494

print(rr)

495

```

496

497

### Creating DNSSEC Records

498

499

```python

500

from dnslib import *

501

502

# DS record for delegation signer

503

ds_record = RR("example.com", QTYPE.DS,

504

rdata=DS(12345, 7, 1, "1234567890ABCDEF1234567890ABCDEF12345678"), ttl=300)

505

print(ds_record)

506

507

# DNSKEY record

508

dnskey_record = RR("example.com", QTYPE.DNSKEY,

509

rdata=DNSKEY(257, 3, 7, "AwEAAcHQ..."), ttl=300)

510

print(dnskey_record)

511

512

# NSEC record

513

nsec_record = RR("example.com", QTYPE.NSEC,

514

rdata=NSEC("mail.example.com", [QTYPE.A, QTYPE.MX, QTYPE.RRSIG, QTYPE.NSEC]), ttl=300)

515

print(nsec_record)

516

```

517

518

### Creating Security Records

519

520

```python

521

from dnslib import *

522

523

# CAA record for certificate authority authorization

524

caa_record = RR("example.com", QTYPE.CAA,

525

rdata=CAA(0, "issue", "letsencrypt.org"), ttl=300)

526

print(caa_record)

527

528

# SSHFP record for SSH key fingerprint

529

sshfp_record = RR("server.example.com", QTYPE.SSHFP,

530

rdata=SSHFP(1, 2, "123456789ABCDEF123456789ABCDEF123456789ABCDEF123456789ABCDEF12"), ttl=300)

531

print(sshfp_record)

532

533

# TLSA record for TLS association

534

tlsa_record = RR("_443._tcp.example.com", QTYPE.TLSA,

535

rdata=TLSA(3, 1, 1, "1234567890ABCDEF..."), ttl=300)

536

print(tlsa_record)

537

```

538

539

### Working with Complex Records

540

541

```python

542

from dnslib import *

543

544

# SOA record with all parameters

545

soa_record = RR("example.com", QTYPE.SOA,

546

rdata=SOA("ns1.example.com", "admin.example.com",

547

(2023010101, 7200, 3600, 604800, 86400)), ttl=300)

548

print(soa_record)

549

550

# LOC record for geographical location

551

loc_record = RR("example.com", QTYPE.LOC,

552

rdata=LOC(37.7749, -122.4194, 10, 1, 10000, 10), ttl=300)

553

print(loc_record)

554

555

# HTTPS service binding record

556

https_record = RR("example.com", QTYPE.HTTPS,

557

rdata=HTTPS(1, ".", {"alpn": "h2,h3"}), ttl=300)

558

print(https_record)

559

```