-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSatuRn v1.1.py
186 lines (149 loc) · 6.77 KB
/
SatuRn v1.1.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#Subnet Mask Calculator in python
# by Crucifery
#V1.1 add :
#Handling Invalid Input
#IP address classes, membership in private or public networks, types of subnets
#Adding input validation
#by Despait
import ipaddress
print("\n-----------------------------------------------")
print("Welcome on SatuRn, a Subnet Mask Calculator \n")
print(""" _.oo.
_.u[[/;:,. .odMMMMMM'
.o888UU[[[/;:-. .o@P^ MMM^
oN88888UU[[[/;::-. dP^
dNMMNN888UU[[[/;:--. .o@P^
,MMMMMMN888UU[[/;::-. o@^
NNMMMNN888UU[[[/~.o@P^
888888888UU[[[/o@^-..
oI8888UU[[[/o@P^:--..
.@^ YUU[[[/o@^;::---..
oMP ^/o@P^;:::---..
.dMMM .o@^ ^;::---...
dMMMMMMM@^` `^^^^
YMMMUP^
^^""")
print("By Crucif3ry, V 1.1")
def main():
while True:
number = input("-----------------------------------------------\n1 - IPv4 Subnet Mask Calculator \n2 - IPv6 Subnet Mask Calculator \n-----------------------------------------------\n\nPlease Enter a Number: ")
if number == '1':
ipv4()
break
if number == '2':
ipv6()
break
print("Invalid input. Please enter a valid number.")
def ipv4():
print("\n-----------------------------------------------")
print("----------IPv4 Subnet Mask Calculator---------- ")
print("-----------------------------------------------\n")
while True:
network_address_ipv4 = input("Enter IPv4 address: ")
subnet_mask_bits = input("Enter Subnet Mask in classic or CIDR format: ")
try:
network_address_ipv4 = ipaddress.IPv4Address(network_address_ipv4)
network = ipaddress.IPv4Network((network_address_ipv4, subnet_mask_bits), strict=False)
broadcast = network.broadcast_address
first_ip = network.network_address + 1
last_ip = broadcast - 1
ipint = int(network_address_ipv4)
ipv4inbinary = bin(ipint)[2:].zfill(32)
smint = int(network.netmask)
subnetmaskinbinary = bin(smint)[2:].zfill(32)
netaddr = int(network.network_address)
netaddrbinary = bin(netaddr)[2:].zfill(32)
brd = int(broadcast)
brdbinary = bin(brd)[2:].zfill(32)
print("\n==========IP ADDRESS===========")
print("IP Address: ", network_address_ipv4)
print("Binary IP Address: ", ipv4inbinary)
print("Integer IP Address: ", ipint)
print("\n==========SUBNET MASK==========")
print("Subnet Mask: ", network.netmask)
print("Subnet Mask in CIDR notation: /", network.prefixlen)
print("Binary Subnet Mask: ", subnetmaskinbinary)
print("\n==========NETWORK ADDRESS==========")
print("Network IP Address: ", network.network_address)
print("Binary Network IP Address: ", netaddrbinary)
print("\n==========BROADCAST==========")
print("Broadcast IP Address: ", broadcast)
print("Binary Broadcast IP Address: ", brdbinary)
print("\n==========AVAILABLE IP==========")
print("Number of available IP Addresses: ", network.num_addresses)
print("Network Range: ", network.network_address, "-", broadcast)
print("\n==========USABLE IP==========")
print("Number of usable IP Addresses: ", len(list(network.hosts())))
print("First usable IP Address: ", first_ip)
print("Last usable IP Address: ", last_ip)
print("\n==========IP TYPE==========")
if network.is_private:
print("Private IP Address")
if network.is_loopback:
print("Loopback Address")
elif network.is_link_local:
print("Link-local Address")
elif network.is_multicast:
print("Multicast Address")
else:
print("Global Unicast Address")
else:
print("Public IP Address")
print("\n==========NETWORK CLASS==========")
if network.is_private:
print("Private Network (RFC 1918)")
elif network.is_reserved:
print("Reserved Network")
elif network.is_multicast:
print("Multicast Network")
elif network.is_loopback:
print("Loopback Network")
elif network.is_link_local:
print("Link-local Network")
else:
print("Public Network")
break
except ipaddress.AddressValueError:
print("Invalid IPv4 address or subnet mask.")
def ipv6():
print("\n-----------------------------------------------")
print("----------IPv6 Subnet Mask Calculator---------- ")
print("-----------------------------------------------\n")
while True:
ipv6_network_str = input("Enter IPv6 address: ")
try:
network = ipaddress.IPv6Network(ipv6_network_str, strict=False)
broadcast = network.broadcast_address
print("\n==========IP ADDRESS===========")
print("IP Address: ", ipv6_network_str)
print("\n==========NETWORK ADDRESS==========")
print("Network IP Address: ", network.network_address)
print("Full Network IP Address: ", network.exploded)
print("\n==========BROADCAST==========")
print("Broadcast IP Address: ", broadcast)
print("\n==========AVAILABLE IP==========")
print("Number of available IP Addresses: ", network.num_addresses)
print("Network Range: ", network.network_address, "-", broadcast)
print("\n==========IP TYPE==========")
if network.is_private:
print("Private IP Address")
else:
print("Public IP Address")
print("\n==========NETWORK CLASS==========")
if network.is_private:
print("Private Network (ULA)")
elif network.is_link_local:
print("Link-local Network")
elif network.is_multicast:
print("Multicast Network")
elif network.is_loopback:
print("Loopback Network")
elif network.is_reserved:
print("Reserved Network")
else:
print("Global Unicast Network")
break
except ipaddress.AddressValueError:
print("Invalid IPv6 address.")
if __name__ == '__main__':
main()