summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--leap/util/net.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/leap/util/net.py b/leap/util/net.py
index 10e72a4..a4104d0 100644
--- a/leap/util/net.py
+++ b/leap/util/net.py
@@ -38,6 +38,23 @@ class PermissionsError(SystemExit):
"""This test requires admin or root privileges to run. Exiting..."""
+def checkIPaddress(addr):
+ """
+ Check that a given string is a valid IPv4 or IPv6 address.
+
+ @param addr: Any string defining an IP address, i.e. '1.2.3.4' or '::1'.
+ @returns: True if :param:`addr` defines a valid IPAddress, else False.
+ """
+ import ipaddr
+
+ try:
+ check = ipaddr.IPAddress(addr)
+ except ValueError, ve:
+ log.warn(ve.message)
+ return False
+ else:
+ return True
+
def getClientPlatform(platform_name=None):
for name, test in PLATFORMS.items():
if not platform_name or platform_name.upper() == name: