File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -537,12 +537,19 @@ def parse_ns_headers(ns_headers):
537537
538538def is_ip (text : str ):
539539 """Return True if text is a valid IP address."""
540- from ipaddress import ip_address
541- text = text . removeprefix ( '[' ). removesuffix ( ']' )
540+ from ipaddress import IPv4Address , IPv6Address
541+ # check for IPv4 address
542542 try :
543- ip_address (text )
543+ IPv4Address (text )
544544 except ValueError :
545- return False
545+ # check for IPv6 address in []
546+ if text .startswith ('[' ) and text .endswith (']' ):
547+ try :
548+ IPv6Address (text .removeprefix ('[' ).removesuffix (']' ))
549+ except ValueError :
550+ return False
551+ else :
552+ return False # not a IPv6 address in []
546553 return True
547554def is_HDN (text ):
548555 """Return True if text is a host domain name."""
You can’t perform that action at this time.
0 commit comments