How to convert a CIDR prefix to a dotted-quad netmask in Python? -
How can I convert a CIDR prefix into a dotted-quad netmask into a dragon?
For example, if the prefix 12
needs me to return 255.240.0.0
.
You can do it like this:
def cidr (Prefix): Return socket.inet_ntoa (struct.pack ("& gt; I", (0xffffffff & lt; (32 - prefix)) & amp; 0xffffffff)
Comments
Post a Comment