summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2013-01-23 19:29:08 +0000
committerIsis Lovecruft <isis@torproject.org>2013-01-23 19:29:08 +0000
commit2b4dfb24b70ae61cd83904cca756c05e3cb781e4 (patch)
tree7a33eaef3acd418eca6d9a0d2ed14d356ae42d4b
parente28d5bf452b025357ae23f87ec34b8ae6897e1fd (diff)
Moved a check on IP addresses to utils/net.py.
-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: