我正在尝试编译Apple设备将拥有的所有MAC地址的列表. oui.txt告诉我Apple已经分配了77个MAC范围.这些范围的形式为:
00:00:00
00:11:11
etc...
这留给我追加的最后三个HEX数字.那是16 ^ 6.共有1291845632个Apple MAC地址.
我遇到的问题是编写一个程序来创建这些MAC地址的列表.这是我目前的代码:
import re
apple_mac_range = []
apple_macs = []
# Parse the HTML of http://standards.ieee.org/cgi-bin/ouisearch to get the MACs
with open('apple mac list', 'r') as f:
for line in f.readlines():
match = re.search(r'[\w\d]{2}-[\w\d]{2}-[\w\d]{2}', line)
if match:
apple_mac_range.append(match.group().split('-'))
for mac in apple_mac_range:
for i in range(1, 1291845633):
print i
这给了我一个MemoryError …我怎样才能优化它?