def mask_dotted_from_bits(bits):
   """Creates a subnet mask string in dotted notation from number of bits."""
   assert bits > 0 
   assert bits <= 32
   mask = '0' * 32
   mask = mask.replace('0', '1', bits)
   dot_mask = '%s.%s.%s.%s' % ( int(mask[:8], 2), int(mask[8:16], 2),
                                int(mask[16:24], 2), int(mask[24:], 2) )
   return dot_mask