1Validate IP Address Python:
2
3def ip_checkv4(ip):
4 parts=ip.split(".")
5 if len(parts)<4 or len(parts)>4:
6 return "invalid IP length should be 4 not greater or less than 4"
7 else:
8 while len(parts)== 4:
9 a=int(parts[0])
10 b=int(parts[1])
11 c=int(parts[2])
12 d=int(parts[3])
13 if a<= 0 or a == 127 :
14 return "invalid IP address"
15 elif d == 0:
16 return "host id should not be 0 or less than zero "
17 elif a>=255:
18 return "should not be 255 or greater than 255 or less than 0 A"
19 elif b>=255 or b<0:
20 return "should not be 255 or greater than 255 or less than 0 B"
21 elif c>=255 or c<0:
22 return "should not be 255 or greater than 255 or less than 0 C"
23 elif d>=255 or c<0:
24 return "should not be 255 or greater than 255 or less than 0 D"
25 else:
26 return "Valid IP address ", ip
27
28 p=raw_input("Enter IP address")
29 print ip_checkv4(p)