]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
add typed variant of MX example
authorBob Halley <halley@dnspython.org>
Fri, 18 Oct 2024 17:27:29 +0000 (10:27 -0700)
committerBob Halley <halley@dnspython.org>
Fri, 18 Oct 2024 17:27:29 +0000 (10:27 -0700)
examples/mx-typed.py [new file with mode: 0755]

diff --git a/examples/mx-typed.py b/examples/mx-typed.py
new file mode 100755 (executable)
index 0000000..41b7c98
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env python3
+
+from typing import cast
+
+import dns.resolver
+from dns.rdtypes.ANY.MX import MX
+
+answers = dns.resolver.resolve("nominum.com", "MX")
+for rdata in answers:
+    mx_rdata = cast(MX, rdata)
+    print("Host", rdata.exchange, "has preference", rdata.preference)