forked from orbit-oss/flask
parent
716edfdb29
commit
c3d49e29ea
2 changed files with 25 additions and 1 deletions
|
|
@ -976,3 +976,23 @@ def total_seconds(td):
|
|||
:rtype: int
|
||||
"""
|
||||
return td.days * 60 * 60 * 24 + td.seconds
|
||||
|
||||
def is_ip(ip):
|
||||
"""Returns the if the string received is an IP or not.
|
||||
|
||||
:param string: the string to check if it an IP or not
|
||||
:param var_name: the name of the string that is being checked
|
||||
|
||||
:returns: True if string is an IP, False if not
|
||||
:rtype: boolean
|
||||
"""
|
||||
import socket
|
||||
|
||||
for family in (socket.AF_INET, socket.AF_INET6):
|
||||
try:
|
||||
socket.inet_pton(family, ip)
|
||||
except socket.error:
|
||||
pass
|
||||
else:
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue