mac:mac地址生成器
madmac的Python项目详细描述
马德马克
测试人员的mac地址生成器库。
内容
安装
使用pip
:
pip install madmac
使用源:
$ git clone https://github.com/laminko/madmac.git
$ cd madmac
$ python setup.py install
使用量
作为命令
可以使用madmac
作为命令。下面将生成随机的mac地址。
madmac
要查看帮助,请输入madmac --help
。
madmac --help usage: madmac [-h][-o OUI][-r START][-s STOP][-t TOTAL][-d DELIMITER][-c CASE] MAC address generator library for testers. optional arguments: -h, --help show this help message and exit -o OUI, --oui OUI 6-digit organizationally unique identifier -r START, --start START NIC specific start address -s STOP, --stop STOP NIC specific end address -t TOTAL, --total TOTAL Number of MACs to generate -d DELIMITER, --delimiter DELIMITER Delimiter for MAC address -c CASE, --case CASE Use lower or upper
NOTE:
madmac
is not a binary file. You need to install python 3.5 to execute the command.
作为模块
从madmac
模块导入MacGenerator
类。使用MacGenerator
创建一个对象并调用其成员generate()
函数。generate()
函数将返回python生成器对象。
下面的代码将使用默认值生成单个mac地址。
frommadmacimportMacGeneratormacg=MacGenerator()macs=macg.generate()# generator object which contains one itemfrompprintimportpprintpprint(list(macs))
默认值如下:
# 'oui': None,# 'start': None,# 'stop': None,# 'total': 1,# 'delimiter': ':',# 'case': 'lower'
我们可以提供oui
:
frommadmacimportMacGeneratormacg=MacGenerator(oui='F0-9F-C2')list(macg.generate())
如果已知,还指定start
地址和end
地址:
frommadmacimportMacGeneratorstart='00-B0-A0'stop='00-B0-DF'macg=MacGenerator(start=start,stop=stop)
NOTE: Above snippet describes to use random
oui
, but to use certain range fromstart
andstop
values. It will ignoretotal
parameter. Delimiter and Case will be default values.
有时,我们可能需要生成一定数量的mac地址:
frommadmacimportMacGeneratormacg=MacGenerator(total=100)