Skip to content

Instantly share code, notes, and snippets.

@saghul
Created June 25, 2014 10:50
Show Gist options
  • Save saghul/81c7f5fe0f0a1ad566ef to your computer and use it in GitHub Desktop.
Save saghul/81c7f5fe0f0a1ad566ef to your computer and use it in GitHub Desktop.
import socket
def is_valid_ip(ip):
r = 0
try:
socket.inet_pton(socket.AF_INET, ip)
except socket.error:
try:
socket.inet_pton(socket.AF_INET6, ip)
except socket.error:
pass
else:
r = 6
else:
r = 4
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment