[python]Netmask to inverse mask

Cisco IOS uses inverse mask in access control list and router network command, only Cisco uses inverse mask instead of actual netmask.

Suppose if the mask is, then the inverse mask is, another example is then the inverse mask is, if you are handling cisco acl with python then there will be a chance inverse mask is used.

Here’s the code to do it.

  • Split the netmask by dot.
  • Subtract each octet by 255.
  • Join the elements in the list by dot in order to get inverse mask
netmask = ""
conversion = [str(255 - int(octet)) for octet in netmask.split(".")]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s