>>> 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
2 comments:
Thank you for this little tidbit of information. I am running python 2.6.6 and experienced an issue with the list generating a string and not able to calculate. I just remapped b to an integer with this line and all works great!!
b = map(int, b)
Script looks as such:
b = "255.255.248.0".split(".")
b = map(int, b)
reduce(lambda x, y: x + (y + 1)/32, b, 0)
There maybe a more elegant way to work this out, but I am in a hurry to finish and just need something to work at this time.
I am a user of the best voip provider and i love it.
Post a Comment