-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathmain.py
66 lines (50 loc) · 1.89 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Solution:
def __init__(self, give_ip: str = None):
ip_subnet = give_ip.split('/')
if len(ip_subnet) < 2:
raise ValueError
ip = ip_subnet[0]
subnet = ip_subnet[1]
ip_dotted = ip.split('.')
if len(ip_dotted) != 4:
raise ValueError
if int(subnet) > 32:
raise ValueError
self.ip_dotted = ip_dotted
self.class_: str = ''
self.designation: str = ''
def kill_it(self):
if self.ip_dotted[0] == '10':
self.class_ = 'A'
self.designation = 'Private'
elif self.ip_dotted[0] == '172' and 16 <= int(self.ip_dotted[1]) <= 31:
self.class_ = 'B'
self.designation = 'Private'
elif self.ip_dotted[0] == '192' and self.ip_dotted[1] == '168':
self.class_ = 'C'
self.designation = 'Private'
elif self.ip_dotted[0] == '192' or 173 <= int(self.ip_dotted[0]) < 224:
self.class_ = 'C'
self.designation = 'Public'
elif self.ip_dotted[0] == '172' or 128 <= int(self.ip_dotted[0]) <= 171:
self.class_ = 'B'
self.designation = 'Public'
elif self.ip_dotted[0] == '127':
self.class_ = 'A'
self.designation = 'Special'
elif 1 < int(self.ip_dotted[0]) <= 126:
self.class_ = 'A'
self.designation = 'Public'
elif 224 <= int(self.ip_dotted[0]) <= 255:
self.class_ = 'D or E'
self.designation = 'Special'
else:
raise ValueError
return f'class: {self.class_}, designation: {self.designation}'
if __name__ == '__main__':
i = input('Please enter an ip address: x.x.x.x/x\n')
try:
solution = Solution(i)
print(solution.kill_it())
except ValueError:
print('Please enter a valid address in this format: x.x.x.x/x')