Move DNS code into dns.py.
Refactor the prefix parsing code a bit.
Preserve the port number if present.