Created
August 8, 2018 07:00
-
-
Save sora/428615a4a64cea886d5f2c1372b9f410 to your computer and use it in GitHub Desktop.
This file contains 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
import struct | |
import re | |
ipfile = open("scanner_uniq.dat", 'r') | |
print('# CIDR, Number_of_prefixes') | |
for cidr in range(1, 33): | |
prefixes = dict() | |
ipfile.seek(0) | |
for line in ipfile: | |
parts = line.rstrip().split('.') | |
addr = (int(parts[0]) << 24) + (int(parts[1]) << 16) + (int(parts[2]) << 8) + int(parts[3]) | |
mask = (0xffffffff >> (32 - cidr)) << (32 - cidr) | |
# print(hex(addr & mask), hex(addr), hex(mask)) | |
pfx = hex(addr & mask) | |
if pfx not in prefixes.keys(): | |
prefixes[pfx] = 0 | |
prefixes[pfx] += 1 | |
print(cidr, "\t", len(prefixes.keys())) | |
ipfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment