AsyncIO for networking

AsyncIO was specifically designed for use with network sockets, so let's implement a DNS server. More accurately, let's implement one extremely basic feature of a DNS server.

The DNS's basic purpose is to translate domain names, such as https://www.python.org/, into IP addresses, such as IPv4 addresses (for example 23.253.135.79) or IPv6 addresses (such as 2001:4802:7901:0:e60a:1375:0:6). It has to be able to perform many types of queries and know how to contact other DNS servers if it doesn't have the answer required. We won't be implementing any of this, but the following example is able to respond directly to a standard DNS query to look up IPs for a few sites:

import asynciofrom contextlib import suppressip_map ...

Get Python 3 Object-Oriented Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.