Skip to content

Instantly share code, notes, and snippets.

@sreimers
Created July 7, 2013 10:33
Show Gist options
  • Save sreimers/5943053 to your computer and use it in GitHub Desktop.
Save sreimers/5943053 to your computer and use it in GitHub Desktop.
Python Check IPv6 IP
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