Added to_ip_address to utils

pull/38/head
Sheng 2018-10-15 17:20:30 +08:00
parent 1e51d690bc
commit a51918d2ac
1 changed files with 5 additions and 2 deletions

View File

@ -30,10 +30,13 @@ def to_int(string):
pass
def to_ip_address(ipstr):
return ipaddress.ip_address(to_str(ipstr))
def is_valid_ip_address(ipstr):
ipstr = to_str(ipstr)
try:
ipaddress.ip_address(ipstr)
to_ip_address(ipstr)
except ValueError:
return False
return True