Last active
February 19, 2021 20:59
-
-
Save Pr1meSuspec7/d6154c4f9b01d2ea80cd5fd51ddfb8eb to your computer and use it in GitHub Desktop.
Function for check if input is an ipv4 address.
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
def check_if_ipv4(ip): | |
quad = ip.split(".") | |
quadinteger = [] | |
try: | |
quadinteger = [int(num) for num in quad] | |
except ValueError: | |
#print('ERROR: Must be an ipv4 address') | |
return | |
while len(quadinteger) != 4: | |
#print('ERROR: Must be four octects') | |
return | |
for octect in quadinteger: | |
if octect > 255 or octect < 0: | |
#print('ERROR: Each octects must be beetween 0 and 255') | |
return | |
return ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment