>>> b = "255.255.248.0".split(".")
to get the bitcount just do:
>>> reduce(lambda x, y: x + (y + 1)/32, b, 0)
23
Modify to taste and njoy
... η μοναξιά του αναβάτη
>>> b = "255.255.248.0".split(".")
>>> reduce(lambda x, y: x + (y + 1)/32, b, 0)
23