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

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -