18.22. 创​​​​​​​建​​​​​​​生​​​​​​​成​​​​​​​ MAC 地​​​​​​​址​​​​​​​的​​​​​​​脚​​​​​​​本​​​​​​​

红​​​​​​​帽​​​​​​​虚​​​​​​​拟​​​​​​​化​​​​​​​系​​​​​​​统​​​​​​​可​​​​​​​以​​​​​​​在​​​​​​​创​​​​​​​建​​​​​​​时​​​​​​​为​​​​​​​每​​​​​​​个​​​​​​​虚​​​​​​​拟​​​​​​​机​​​​​​​生​​​​​​​成​​​​​​​一​​​​​​​个​​​​​​​ MAC 地​​​​​​​址​​​​​​​。​​​​​​​虽​​​​​​​然​​​​​​​在​​​​​​​同​​​​​​​一​​​​​​​子​​​​​​​网​​​​​​​里​​​​​​​几​​​​​​​乎​​​​​​​可​​​​​​​以​​​​​​​有​​​​​​​无​​​​​​​限​​​​​​​个​​​​​​​可​​​​​​​用​​​​​​​选​​​​​​​择​​​​​​​,你​​​​​​​仍​​​​​​​有​​​​​​​可​​​​​​​能​​​​​​​获​​​​​​​得​​​​​​​相​​​​​​​同​​​​​​​的​​​​​​​ MAC 地​​​​​​​址​​​​​​​。​​​​​​​要​​​​​​​绕​​​​​​​过​​​​​​​这​​​​​​​个​​​​​​​问​​​​​​​题​​​​​​​,你​​​​​​​可​​​​​​​以​​​​​​​编​​​​​​​写​​​​​​​一​​​​​​​个​​​​​​​脚​​​​​​​本​​​​​​​来​​​​​​​生​​​​​​​成​​​​​​​ MAC 地​​​​​​​址​​​​​​​。​​​​​​​下​​​​​​​面​​​​​​​是​​​​​​​一​​​​​​​个​​​​​​​生​​​​​​​成​​​​​​​ MAC 地​​​​​​​址​​​​​​​的​​​​​​​包​​​​​​​含​​​​​​​参​​​​​​​数​​​​​​​的​​​​​​​脚​​​​​​​本​​​​​​​示​​​​​​​例​​​​​​​:
#! /usr/bin/python
# macgen.py script generates a MAC address for Xen guests
#
import random
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
print ':'.join(map(lambda x: "%02x" % x, mac))

Generates e.g.:
00:16:3e:66:f5:77
to stdout

为了尽快向用户提供最新的信息,本文档可能会包括由机器自动从英文原文翻译的内容。如需更多信息,请参阅此说明。