summaryrefslogtreecommitdiff
path: root/kvmd/validators/net.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-04-22 21:28:27 +0300
committerDevaev Maxim <[email protected]>2020-04-22 21:28:27 +0300
commit820ef178710d8442e30c5b23d0ac0cb90be5150c (patch)
tree2b9954ad5fc206565463962c0c980c2eca2e0e06 /kvmd/validators/net.py
parent1bb0d725fac36a78e0fbfc1ac843eeef73f7ca04 (diff)
using ipaddress module in vlaidators
Diffstat (limited to 'kvmd/validators/net.py')
-rw-r--r--kvmd/validators/net.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/kvmd/validators/net.py b/kvmd/validators/net.py
index 79d46a15..247122cd 100644
--- a/kvmd/validators/net.py
+++ b/kvmd/validators/net.py
@@ -20,7 +20,7 @@
# ========================================================================== #
-import socket
+import ipaddress
from typing import List
from typing import Callable
@@ -50,9 +50,9 @@ def valid_ip(arg: Any, v4: bool=True, v6: bool=True) -> str:
assert v4 or v6
validators: List[Callable] = []
if v4:
- validators.append(lambda arg: (arg, socket.inet_pton(socket.AF_INET, arg))[0])
+ validators.append(lambda arg: str(ipaddress.IPv4Address(arg)))
if v6:
- validators.append(lambda arg: (arg, socket.inet_pton(socket.AF_INET6, arg))[0])
+ validators.append(lambda arg: str(ipaddress.IPv6Address(arg)))
name = "IP address"
return check_any(
arg=valid_stripped_string_not_empty(arg, name),