Welcome to www.sevenever.com
Something about programming, Linux, geek...You need a file which has only one copy on your home PC's harddisk, but you are in office or another city even another country! What would you do? Call your neighbor to ask him break into your house and power on your PC, then you can fetch file by sftp?
Here is the solution to avoid breaking your door. Remote Power On
Thanks for WOL tech and Python, It's so easy!
What We need:
1. A WOL(wake on lan) supported NIC
My Asus K8N integrated NIC
2. A tool to send Magic Package
A Python script no more than 40 lines
3. An ADLS router supporting DDNS, ARP binding and NAT port mapping
TP-Link WR541G/542G
Here is steps:
1. Enable WOL in BIOS settings.
There are a bunch of guides on google, find one for your motherboard and network card. Notice: ACPI 2.0 must be enabled, I wasted hours before success on this misconfig.
2. save script below as wol.py
#!/usr/bin/python
import sys
import struct
from socket import *
def usage():
print """send UDP packet to broadcasting address to remote wakeup
UDP package format is FFFFFFFFFFFF0017314BACCB....................
(fixed 6 FF)( mac )(repeat mac 15 times)
usage: wol.py broadcasting_address udp_port target_host_mac
example: wol.py sevenever.vicp.net 4672 0017314BACCB
"""
def main():
if len(sys.argv) != 4:
usage()
return 1
bc_addr = sys.argv[1]
udp_port = int(sys.argv[2])
mac = sys.argv[3]
hw_addr = struct.pack('BBBBBB', int(mac[0:2], 16),
int(mac[2:4], 16),
int(mac[4:6], 16),
int(mac[6:8], 16),
int(mac[8:10], 16),
int(mac[10:12], 16))
msg = '\xff' * 6 + hw_addr * 16
sk = socket(AF_INET, SOCK_DGRAM)
sk.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
sk.sendto(msg, (bc_addr, udp_port))
sk.close()
if __name__ == '__main__':
sys.exit(main())
3. Setting on your router
3.1 add an arp binding record
[your PC IP address] ---- [your netcard MAC address]
say:[192.168.1.7] ---- [00-11-D8-93-E9-08]
3.2 add a NAT port mapping
since the tool above send UDP package to your router, your router must know how to forward package to your PC, So
add a port mapping:
Protocol: UDP
Service Port: any (say 4672)
LAN Host IP: The IP binded in step 3.1
*may be you have had an UDP port mapping for edonkey or some application else, if so you can just reuse that setting and do nothing for this step 3.2.
3.3 setup DDNS on router
The last thing is you must know your router's Internet Address, if your ISP assign you a fixed pulic IP(lucky guy! that's impossible for China where I living), you just remember it, or you need setup DDNS( like oray.net or 3322.org ). Google it, you will find lots of guides. Here I asume you can access your router by name: somename.3322.org.
Now we have done all settings, The command for power on our home PC remotely in office or anywhere is:
./wol.py somename.3322.org 4672 0011D893E908
Enjoy!