summaryrefslogtreecommitdiffstats
path: root/ipalib/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'ipalib/util.py')
-rw-r--r--ipalib/util.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/ipalib/util.py b/ipalib/util.py
index 1803e65ab..0f84b7975 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -170,3 +170,18 @@ def isvalid_base64(data):
return False
else:
return True
+
+def validate_ipaddr(ipaddr):
+ """
+ Check to see if the given IP address is a valid IPv4 or IPv6 address.
+
+ Returns True or False
+ """
+ try:
+ socket.inet_pton(socket.AF_INET, ipaddr)
+ except socket.error:
+ try:
+ socket.inet_pton(socket.AF_INET6, ipaddr)
+ except socket.error:
+ return False
+ return True