Write the Telegram Yourself
Tap the board to zoom inClick the board to zoom in
Lessons that use this board
Write the telegram yourself — 29 bytes, no libraries
the capstone: lessons 1–3 typed by hand in ~30 lines of Python and mailed for real. everything below is from the run just now.
the recipe
1 · pick a random tag (yours came out 0a 04) — so you
recognize YOUR reply among everyone's mail
2 · spell the name telegram-style: 7·example 3·com end
3 · say what you want: the house number, internet class
4 · drop it in the UDP mailbox at the doorman's desk
(port 53 — the mail slot every doorman watches)
…then just listen.
the 29 bytes you mailed:
0a 04
your tag
01 00
"please recurse"
00 01 00 00 00 00 00 00
one question, nothing else
07
7→
65 78 61 6d 70 6c 65
e x a m p l e
03
3→
63 6f 6d
c o m
00
end
00 01
house no.
00 01
internet
(65 78 61 6d 70 6c 65 is just "example" in a letter-numbering everyone agreed on in the 1960s — nothing mystical)
what came back, 12 ms later:
reply : 61 bytes
house : 104.20.23.154 (valid 68s)
house : 172.66.147.243 (valid 68s)
← the sticky note had 68 seconds left this
time — we caught it mid-countdown
why this is the whole game
no magic left. every browser, every app,
every library is doing exactly this —
composing small byte-messages and
mailing them. you just did it by hand.
play with it
python3 teaching/code/dns_telegram.py
· change NAME to any website
· change CONCIERGE to "1.1.1.1"
· break it on purpose: make a length
byte wrong and watch the silence —
doormen bin malformed telegrams
without a word
where you feel this: every "is this
site down?" checker, every ad-blocker
DNS, every smart-home gadget speaks
exactly these 29 bytes.
the only new jargon left:
struct.pack = "write these numbers down as raw bytes" socket = "a handle on the mailbox"
the script lives at teaching/code/dns_telegram.py — 30 readable lines, yours to break and rebuild.
THE 29 BYTES, DECODED -- the exact query your code built
1) EVERY BYTE OF THE QUERY
HEADER (12 bytes):
1234 = ID (any number)
0100 = flags: RD=1 (please recurse)
0001 0000 0000 0000 = QD=1, AN=NS=AR=0
QUESTION (13 bytes):
07 'example' 03 'com' 00 = QNAME
0001 = QTYPE A 0001 = QCLASS IN
12 + 13 + 4 = 29 bytes. that is the entire telegram.
2) THE WHOLE PROGRAM (no libraries)
s = socket(AF_INET, SOCK_DGRAM) # a UDP socket
s.sendto(query, ('1.1.1.1', 53)) # fire the 29 bytes
resp, _ = s.recvfrom(512) # the answer
# skip the 12-byte header,
# walk past the echoed question,
# read RDLENGTH = 4 -> the 4 IP bytes
struct.pack + socket. you did the resolver's whole job by hand.
Saved in this browser only.