Not only is there struct, but also scapy which can craft any packet with ease. A quick Google search shows DNS examples, https://thepacketgeek.com/scapy/building-network-tools/part-09/.
Combining asyncio with uvloop also provides very good performance. Ryan Hamel ________________________________ From: John Levine via NANOG <[email protected]> Sent: Sunday, August 10, 2025 5:56 PM To: [email protected] <[email protected]> Cc: John Levine <[email protected]> Subject: Re: Speaking of DNS server software... Caution: This is an external email and may be malicious. Please take care when clicking links or opening attachments. It appears that William Herrin via NANOG <[email protected]> said: >Python doesn't work this way. Its memory management is abstracted away >from the programmer and the programmer does not control its precise >structure. For Python to access a DNS packet, the programmer must pack >and unpack an array of bytes using complex software of their own >devising. You can't just tell Python, "This is the complex data >structure these bytes contain, let me access the data without >unpacking it." The python struct module is pretty fast, since it's written in C. I recently rewrote the abuse.net DNS server in python doing white lies on the fly DNSSEC signing. It's fast enough. R's, John _______________________________________________ NANOG mailing list https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.nanog.org%2Farchives%2Flist%2Fnanog%40lists.nanog.org%2Fmessage%2FBGFDLG24XEHD47QE77ST6LY4OXUMHIKS%2F&data=05%7C02%7Cryan%40rkhtech.org%7C7acd43e68c4640cba83208ddd87271ce%7C81c24bb4f9ec4739ba4d25c42594d996%7C0%7C0%7C638904708244791010%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=VjAtZulg33OR7sZwZBVoRhMmndVN6Lzzm2TISqmU5xM%3D&reserved=0<https://lists.nanog.org/archives/list/[email protected]/message/BGFDLG24XEHD47QE77ST6LY4OXUMHIKS/> _______________________________________________ NANOG mailing list https://lists.nanog.org/archives/list/[email protected]/message/R6SG7AWZIY4WGGMK3YQGIXGP3TUZ6AV3/
