Created
August 25, 2021 23:19
-
-
Save subtosilencio/78db52be8d6bdb952dfca694104f3130 to your computer and use it in GitHub Desktop.
Verify IP Address Validity
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 is_valid_ipv4_address(address): | |
''' Verify IP Address Validity ''' | |
try: | |
socket.inet_pton(socket.AF_INET, address) | |
except AttributeError: # no inet_pton here, sorry | |
try: | |
socket.inet_aton(address) | |
except socket.error: | |
return False | |
return address.count('.') == 3 | |
except socket.error: # not a valid address | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment