-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip.py
155 lines (146 loc) · 4.88 KB
/
ip.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import re
def slash_to_mask(self, slash):
slash = str(slash)
if slash[0] == "3":
if slash[1] == "2":
return "255.255.255.255"
if slash[1] == "1":
return "255.255.255.254"
if slash[1] == "0":
return "255.255.255.252"
if slash[0] == "2":
if slash[1] == "9":
return "255.255.255.248"
if slash[1] == "8":
return "255.255.255.240"
if slash[1] == "7":
return "255.255.255.224"
if slash[1] == "6":
return "255.255.255.192"
if slash[1] == "5":
return "255.255.255.128"
if slash[1] == "4":
return "255.255.255.0"
if slash[1] == "3":
return "255.255.254.0"
if slash[1] == "2":
return "255.255.252.0"
if slash[1] == "1":
return "255.255.248.0"
if slash[1] == "0":
return "255.255.240.0"
if slash[0] == "1":
if slash[1] == "9":
return "255.255.224.0"
if slash[1] == "8":
return "255.255.192.0"
if slash[1] == "7":
return "255.255.128.0"
if slash[1] == "6":
return "255.255.0.0"
if slash[1] == "5":
return "255.254.0.0"
if slash[1] == "4":
return "255.252.0.0"
if slash[1] == "3":
return "255.248.0.0"
if slash[1] == "2":
return "255.240.0.0"
if slash[1] == "1":
return "255.224.0.0"
if slash[1] == "0":
return "255.192.0.0"
if slash == "9":
return "255.128.0.0"
if slash == "8":
return "255.0.0.0"
if slash == "7":
return "254.0.0.0"
if slash == "6":
return "252.0.0.0"
if slash == "5":
return "248.0.0.0"
if slash == "4":
return "240.0.0.0"
if slash == "3":
return "224.0.0.0"
if slash == "2":
return "192.0.0.0"
if slash == "1":
return "128.0.0.0"
if slash == "0":
return "0.0.0.0"
return None
def mask_to_slash(self, mask):
mask = str(mask).split(".")
if mask[0] == "255":
if mask[1] == "255":
if mask[2] == "255":
if mask[3] == "255":
return 32
if mask[3] == "254":
return 31
if mask[3] == "252":
return 30
if mask[3] == "248":
return 29
if mask[3] == "240":
return 28
if mask[3] == "224":
return 27
if mask[3] == "192":
return 26
if mask[3] == "128":
return 25
if mask[3] == "0":
return 24
if mask[2] == "254" and mask[3] == "0":
return 23
if mask[2] == "252" and mask[3] == "0":
return 22
if mask[2] == "248" and mask[3] == "0":
return 21
if mask[2] == "240" and mask[3] == "0":
return 20
if mask[2] == "224" and mask[3] == "0":
return 19
if mask[2] == "192" and mask[3] == "0":
return 18
if mask[2] == "128" and mask[3] == "0":
return 17
if mask[2] == "0" and mask[3] == "0":
return 16
if mask[1] == "254" and mask[2] == "0" and mask[3] == "0":
return 15
if mask[1] == "252" and mask[2] == "0" and mask[3] == "0":
return 14
if mask[1] == "248" and mask[2] == "0" and mask[3] == "0":
return 13
if mask[1] == "240" and mask[2] == "0" and mask[3] == "0":
return 12
if mask[1] == "224" and mask[2] == "0" and mask[3] == "0":
return 11
if mask[1] == "192" and mask[2] == "0" and mask[3] == "0":
return 10
if mask[1] == "128" and mask[2] == "0" and mask[3] == "0":
return 9
if mask[1] == "0" and mask[1] == "0" and mask[1] == "0":
return 8
if mask[0] == "254" and mask[1] == "0" and mask[2] == "0" and mask[3] == "0":
return 7
if mask[0] == "252" and mask[1] == "0" and mask[2] == "0" and mask[3] == "0":
return 6
if mask[0] == "248" and mask[1] == "0" and mask[2] == "0" and mask[3] == "0":
return 5
if mask[0] == "240" and mask[1] == "0" and mask[2] == "0" and mask[3] == "0":
return 4
if mask[0] == "224" and mask[1] == "0" and mask[2] == "0" and mask[3] == "0":
return 3
if mask[0] == "192" and mask[1] == "0" and mask[2] == "0" and mask[3] == "0":
return 2
if mask[0] == "128" and mask[1] == "0" and mask[2] == "0" and mask[3] == "0":
return 1
if mask[0] == "0" and mask[1] == "0" and mask[2] == "0" and mask[3] == "0":
return 0
def get_count(self, slash):
pass