From 037dfe7f71f21e37fade0e3a203e38b675a1aa43 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Mon, 18 May 2020 08:07:47 -0700 Subject: [PATCH] add is_address() --- dns/inet.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dns/inet.py b/dns/inet.py index 62719dc9..254b5d07 100644 --- a/dns/inet.py +++ b/dns/inet.py @@ -120,3 +120,22 @@ def is_multicast(text): return first == 255 except Exception: raise ValueError + + +def is_address(text): + """Is the specified string an IPv4 or IPv6 address? + + *text*, a ``str``, the textual address. + + Returns a ``bool``. + """ + + try: + dns.ipv4.inet_aton(text) + return True + except Exception: + try: + dns.ipv6.inet_aton(text, True) + return True + except Exception: + raise False -- 2.47.3