我正在尝试运行python脚本向我网络上的计算机发送魔术包。它适用于其他计算机,但当我尝试使用自己的MAC地址运行脚本时,我收到错误。
这是我的python脚本
#!/usr/bin/env python
#Wake-On-LAN
#
# Copyright (C) 2002 by Micro Systems Marc Balmer
# Written by Marc Balmer, marc@msys.ch, http://www.msys.ch/
# This code is free software under the GPL
import struct, socket
def WakeOnLan(ethernet_address):
# Construct a six-byte hardware address
addr_byte = ethernet_address.split(':')
hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16),
int(addr_byte[1], 16),
int(addr_byte[2], 16),
int(addr_byte[3], 16),
int(addr_byte[4], 16),
int(addr_byte[5], 16))
# Build the Wake-On-LAN "Magic Packet"...
msg = b'\xff' * 6 + hw_addr * 16
# ...and send it to the broadcast address using UDP
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto(msg, ('10.0.0.129', 9))
s.sendto(msg, ('10.0.0.129', 7))
s.close()
# Example use
WakeOnLan('30-5A-3A-03-82-AE')
10.0.0.129是我的本地地址,30-5A-3A-03-82-AE是我的实际地址。
当我尝试运行脚本时,我收到此错误
Traceback (most recent call last):
File "C:\xampp\htdocs\wol\wolme.py", line 35, in <module>
WakeOnLan('30-5A-3A-03-82-AE')
File "C:\xampp\htdocs\wol\wolme.py", line 15, in WakeOnLan
hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16),
ValueError: invalid literal for int() with base 16: '30-5A-3A-03-82-AE'
同样,没有其他计算机出现此问题。任何帮助表示赞赏。
答案 0 :(得分:0)
它不适用于以“ - ”分隔的任何地址,因为这一行:
addr_byte = ethernet_address.split(':')
只需使用WakeOnLan('30-5A-3A-03-82-AE')
更改WakeOnLan('30:5A:3A:03:82:AE')
即可使用,或者更改说明的行:
addr_byte = ethernet_address.split(':')
与
addr_byte = ethernet_address.split('-')
如果你想使用“ - ”作为分隔符。
希望这有帮助!