Last active
October 8, 2019 03:49
-
-
Save ndaidong/b3c0d6db2eeaac86e2e75b0a3ca56b90 to your computer and use it in GitHub Desktop.
Counting number of IP belongs to a subnetmask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from functools import reduce | |
from collections import Counter | |
def ip_count(netmask): | |
tmp = list(map(lambda x: bin(int(x)), netmask.split('.'))) | |
arr = list(reduce(lambda x, y: x + y, tmp)) | |
counter = Counter(arr) | |
return counter['1'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Result: