-
-
Save saghul/81c7f5fe0f0a1ad566ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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