How to check the validity of an IP address and classify them (python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to check the validity of an IP address and classify them (python)

27th Oct 2020, 9:51 PM
Cyril Kevin
3 Answers
27th Oct 2020, 11:05 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
+ 2
# Python program to validate an Ip address #By Galaxy-Coding import re regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)
#x27;'' def check(Ip): if(re.search(regex, Ip)): print("Valid Ip address") else: print("Invalid Ip address") if __name__ == '__main__' : Ip = input() check(Ip)
27th Oct 2020, 11:05 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
0
thanks a lot😀
28th Oct 2020, 2:11 AM
Cyril Kevin