File tree 1 file changed +46
-0
lines changed
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Checking valid Ip Address.
3
+ A valid IP address must be in the form of A.B.C.D,
4
+ where A,B,C and D are numbers from 0-254
5
+ for example: 192.168.23.1, 172.254.254.254 are valid IP address
6
+ 192.168.255.0, 255.192.3.121 are Invalid IP address
7
+ """
8
+
9
+
10
+ def check_valid_ip (ip : str ) -> bool :
11
+ """
12
+ print "Valid IP address" If IP is valid.
13
+ or
14
+ print "Invalid IP address" If IP is Invalid.
15
+
16
+ >>> check_valid_ip("192.168.0.23")
17
+ True
18
+
19
+ >>> check_valid_ip("192.255.15.8")
20
+ False
21
+
22
+ >>> check_valid_ip("172.100.0.8")
23
+ True
24
+
25
+ >>> check_valid_ip("254.255.0.255")
26
+ False
27
+ """
28
+ ip1 = ip .replace ("." , " " )
29
+ list1 = [int (i ) for i in ip1 .split () if i .isdigit ()]
30
+ count = 0
31
+ for i in list1 :
32
+ if i > 254 :
33
+ count += 1
34
+ break
35
+ if count :
36
+ return False
37
+ return True
38
+
39
+
40
+ if __name__ == "__main__" :
41
+ ip = input ()
42
+ output = check_valid_ip (ip )
43
+ if output is True :
44
+ print (f"{ ip } is a Valid IP address" )
45
+ else :
46
+ print (f"{ ip } is an Invalid IP address" )
You can’t perform that action at this time.
0 commit comments