# Dns message parse

`dns-message-parse` · version 1.0.0 · Communications · free, no key needed

Parse a DNS message hex string into the RFC 1035 header, questions, and resource records.

**Use when you need to: parse dns message wire hex · decode rfc 1035 dns packet · read dns header questions and records.**

## Decide before calling

Read the [versioned contract](/v1/tools/dns-message-parse/versions/1.0.0) and the supported scope below. Reuse `dns-message-parse@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `dns-message-parse@1.0.0` for parse dns message wire hex. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- parse dns message wire hex
- decode rfc 1035 dns packet
- read dns header questions and records
- expand compressed names in a dns message
- dns query packet hex to fields
- structured fields from a dns message
- פענוח הודעת די אן אס מקוד הקס

## Not supported

- resolve a dns name on the network
- validate dnssec signatures or check AD and CD
- decode A MX TXT or SOA rdata into fields
- convert a name to punycode

## Behavior

- Input message_hex is lowercase even-length hexadecimal of one RFC 1035 message, with no TCP length prefix.
- The header returns every RFC 1035 Section 4.1.1 field. QR, AA, TC, RD and RA are booleans. Opcode is an integer 0..15 and RCODE is an integer 0..15. Z is an integer 0..7 covering diagram columns 9 through 11; AD and CD are not separate fields, so flags 0x0070 yield z 7.
- Questions and records keep unknown type and class codes. RDATA other than an OPT record is preserved as lowercase rdata_hex and is not interpreted.
- An OPT record (type 41) is accepted only in the additional section, only with the root name, and at most once. Its CLASS, TTL and RDATA are also returned as udp_payload_size, extended RCODE, version, dnssec_ok (the DO bit), a 15-bit z, and option tuples. Unknown option codes are kept.
- Compression pointers must target an earlier offset. A pointer cycle is compression_loop. The TC bit is preserved and does not by itself make a complete message invalid. Header counts must match the records present; leftover bytes are trailing_bytes.
- Names are absolute. Parsing emits a canonical presentation: dot-separated labels, root as ".", printable ASCII other than "." and "\" as itself, and every other octet as a three-digit decimal escape. Letter case is preserved.
- Caps are enforced before or during the walk: message bytes, total records, name octets, label octets, pointer hops, RDATA bytes and OPT options. A count above the record cap fails before the body is read.
- Disclaimer: format transform only; provides no confidentiality, integrity, or authenticity.

## Input

- `message_hex` (string, required): min length 0; max length 1024; pattern `^([0-9a-f]{2})*$`

## Output

- `header` (object, required)
- `questions` (array of object, required): max items 32
- `answers` (array of object, required): max items 32
- `authority` (array of object, required): max items 32
- `additional` (array of object, required): max items 32

## Limits

- max message bytes: 512
- max hex chars: 1024
- max records: 32
- max name octets: 255
- max label octets: 63
- max pointer hops: 16
- max rdata bytes: 489
- max opt options: 16

## Example

Request input:

```json
{
  "message_hex": "03e50800000000010000000000000100010000000000040a010034"
}
```

Response:

```json
{
  "result": {
    "header": {
      "id": 997,
      "qr": false,
      "opcode": 1,
      "aa": false,
      "tc": false,
      "rd": false,
      "ra": false,
      "z": 0,
      "rcode": 0,
      "qdcount": 0,
      "ancount": 1,
      "nscount": 0,
      "arcount": 0
    },
    "questions": [],
    "answers": [
      {
        "name": ".",
        "type": 1,
        "class": 1,
        "ttl": 0,
        "rdata_hex": "0a010034",
        "opt": null
      }
    ],
    "authority": [],
    "additional": []
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "dns-message-parse",
  "version": "1.0.0",
  "input": {
    "message_hex": "03e50800000000010000000000000100010000000000040a010034"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/dns-message-parse/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"message_hex":"03e50800000000010000000000000100010000000000040a010034"}'
```

The machine-readable contract is at [/v1/tools/dns-message-parse/versions/1.0.0](/v1/tools/dns-message-parse/versions/1.0.0).

### CLI

```sh
node cli.mjs run dns-message-parse 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Dns message encode](/tools/dns-message-encode): Encode a structured DNS message to canonical uncompressed RFC 1035 wire hex.
- [Dns header flags explain](/tools/dns-header-flags-explain): Explain an RFC 1035 DNS header flags word, with reserved Z as an integer 0 through 7.
- [Email address list parse](/tools/email-address-list-parse): Parse an RFC 5322 address-list into ordered mailboxes, groups, and a canonical form.
- [Dns rdata decode](/tools/dns-rdata-decode): Decode DNS RDATA hex for A, AAAA, NS, CNAME, PTR, MX, TXT, SOA, SRV, or unknown.
- [Email address list format](/tools/email-address-list-format): Format mailboxes and groups as one deterministic RFC 5322 address-list.
- [Dns message validate](/tools/dns-message-validate): Validate DNS message hex structure: counts, names, compression, and OPT records.
