A Python subnet calculator class using built-in ipaddress module
- def Broadcast(self)
- def Cidr(self)
- def FirstAddress(self)
- def Hosts(self)
- def HostAddress(self)
- def LastAddress(self)
- def Mask(self)
- def Netmask(self)
- def NetworkAddress(self)
- def Range(self)
- def Size(self)
- def subNetworks(self, newPrefix: int = 0, subnetMask: str=None)
- def parentNetwork(self, newPrefix: int = 0, prefixlenDiff: int = 0)
- def toString(self)
- def Wildcard(self)
Retrieve informations about a given CIDR IP address
from libraries.tools import subnetCalculator
if __name__ == '__main__':
prefix = input('Enter IP address in IP/Mask Form : ')
net = subnetCalculator(prefix)
net.toString()
# print('Hosts List : ' , net.Hosts())
print('Parent Network : ' , net.parentNetwork(prefixlenDiff=1))
print('Subnets Blocks : ' , net.subNetworks(newPrefix=25))
Enter IP address in IP/Mask Form : 192.168.0.0/16
Host Address : 192.168.0.0
Network Address : 192.168.0.0
Subnet Mask : 255.255.0.0
Mask : /16
CIDR Notation : 192.168.0.0/16
Broadcast Address : 192.168.255.255
Wildcard Mask : 0.0.255.255
First IP : 192.168.0.1
Last IP : 192.168.255.254
Range : 192.168.0.1-192.168.255.254
Hosts Count : 65534