Skip to content

Instantly share code, notes, and snippets.

@Pr1meSuspec7
Last active February 19, 2021 20:59
Show Gist options
  • Save Pr1meSuspec7/d6154c4f9b01d2ea80cd5fd51ddfb8eb to your computer and use it in GitHub Desktop.
Save Pr1meSuspec7/d6154c4f9b01d2ea80cd5fd51ddfb8eb to your computer and use it in GitHub Desktop.
Function for check if input is an ipv4 address.
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