'WOL MAC Address not working
I'm trying to run a python script to send a magic packet to computers on my network. It works on the other computers, but when I try to run the script with my own MAC address I get an error.
This is my python script
#!/usr/bin/env python
#Wake-On-LAN
#
# Copyright (C) 2002 by Micro Systems Marc Balmer
# Written by Marc Balmer, [email protected], 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')
With 10.0.0.129 being my local address and 30-5A-3A-03-82-AE being my physical address.
When I try to run the script I get this error
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'
Again, no other computer has this problem. Any help appreciated.
Solution 1:[1]
it won't work on any address separated by "-", because of this line:
addr_byte = ethernet_address.split(':')
just change WakeOnLan('30-5A-3A-03-82-AE')
with WakeOnLan('30:5A:3A:03:82:AE')
and it will work, or instead change the line that says:
addr_byte = ethernet_address.split(':')
with
addr_byte = ethernet_address.split('-')
if you want to use "-" as separators.
Hope this helps!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Juan AlbarracĂn |