diff options
author | Devaev Maxim <[email protected]> | 2020-04-22 21:28:27 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-04-22 21:28:27 +0300 |
commit | 820ef178710d8442e30c5b23d0ac0cb90be5150c (patch) | |
tree | 2b9954ad5fc206565463962c0c980c2eca2e0e06 /kvmd/validators/net.py | |
parent | 1bb0d725fac36a78e0fbfc1ac843eeef73f7ca04 (diff) |
using ipaddress module in vlaidators
Diffstat (limited to 'kvmd/validators/net.py')
-rw-r--r-- | kvmd/validators/net.py | 6 |
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), |