import socket
mac = "00:00:00:00:00:00" # mac address
decoded = "" # string for converting characters to hex
package = mac.split(':') # remove ':''
# iterate through mac address and convert to hex 2 characters at a time
for x in package:
decoded += x.decode('hex')
macAddress = '\xff'*6+decoded*16 # magic package!
#method for sending magic package
def wakeOnLan(mac):
mySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
mySocket.sendto(mac, ('255.255.255.255', 9)) # broadcast address and port
mySocket.close()
wakeOnLan(macAddress) # Send it away baby!
---
Short version(where you have to manually edit the mac address):
import socket
macAddress = '\xff'*6+'\x00\x00\x00\x00\x00\x00'*16
def wakeOnLan(mac):
mySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mySocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
mySocket.sendto(mac, ('255.255.255.255', 9))
mySocket.close()
wakeOnLan(macAddress)
No comments:
Post a Comment