Created
July 7, 2013 10:33
-
-
Save sreimers/5943053 to your computer and use it in GitHub Desktop.
Python Check IPv6 IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
def check_ipv6(n): | |
try: | |
socket.inet_pton(socket.AF_INET6, n) | |
return True | |
except socket.error: | |
return False | |
print check_ipv6('::1') # True | |
print check_ipv6('foo') # False | |
print check_ipv6(5) # TypeError exception | |
print check_ipv6(None) # TypeError exception |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment