我编写了一堆Python
脚本,允许我使用Python
. 例如,该wake on LAN
脚本使用网络发送初始化机器启动的数据包。问题是:我正在运行一些性能测试,并且我在一个桌面上安装了 12 个不同版本的 Windows(7、8 和 Blue,x86 和 x64)所以当启动启动时,会出现选择哪个机器启动。一旦我弄清楚了这个数字,那么我就完成了。是否有任何 python 库,或者任何可以运行的东西Python
可以控制启动哪台机器?例如,假设我们在启动引导中有installs A
、B
和C
D
. 例如,有没有一种方法可以检索这些选项的列表,然后选择引导B
启动?除此之外,我已经弄清楚了整个应用程序。这是脚本Wake on LAN
:
#!/usr/bin/env python
# wol.py
import socket
import struct
def wake_on_lan(macaddress):
""" Switches on remote computers using WOL. """
# Check macaddress format and try to compensate.
if len(macaddress) == 12:
pass
elif len(macaddress) == 12 + 5:
sep = macaddress[2]
macaddress = macaddress.replace(sep, '')
else:
raise ValueError('Incorrect MAC address format')
# Pad the synchronization stream.
data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
send_data = ''
# Split up the hex values and pack.
for i in range(0, len(data), 2):
send_data = ''.join([send_data,
struct.pack('B', int(data[i: i + 2], 16))])
# Broadcast it to the LAN.
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(send_data, ('<broadcast>', 7))
if __name__ == '__main__':
# Use macaddresses with any seperators.
wake_on_lan('0F:0F:DF:0F:BF:EF')
wake_on_lan('0F-0F-DF-0F-BF-EF')
# or without any seperators.
wake_on_lan('0F0FDF0FBFEF')