glogglog

Remote awake over Internet

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!

 

 

 



Tags: python | WOL | DDNS |

Blogs refer to this post:
Casino 1242851951:Casino 1242851951
Casino 1243292063:Casino 1243292063
Casino 1243310835:Casino 1243310835
Casino 1243378807:Casino 1243378807
Casino 1243379947:Casino 1243379947
Casino 1243384200:Casino 1243384200
Casino 1243695682:Casino 1243695682
Casino 1243732030:Casino 1243732030
Casino 1243756825:Casino 1243756825
Casino 1243769709:Casino 1243769709
Casino 1243791542:Casino 1243791542
Casino 1243804795:Casino 1243804795
Casino 1243807815:Casino 1243807815
Casino 1243899951:Casino 1243899951
Casino 1243909258:Casino 1243909258
Casino 1243916586:Casino 1243916586
Casino 1243918712:Casino 1243918712
Casino 1243939549:Casino 1243939549
Casino 1243941945:Casino 1243941945
Casino 1243945960:Casino 1243945960
Casino 1243971005:Casino 1243971005
Casino 1243975296:Casino 1243975296
Casino 1243987355:Casino 1243987355
Casino 1244001087:Casino 1244001087
Casino 1244030926:Casino 1244030926
Casino 1244054923:Casino 1244054923
Casino 1244059481:Casino 1244059481
Casino 1244078925:Casino 1244078925
Casino 1244091308:Casino 1244091308
Casino 1244110053:Casino 1244110053
Casino 1244114512:Casino 1244114512
Casino 1244152225:Casino 1244152225
Casino 1244160721:Casino 1244160721
Casino 1244170341:Casino 1244170341
Casino 1244189844:Casino 1244189844
Casino 1244210426:Casino 1244210426
Casino 1244252129:Casino 1244252129
Casino 1244288291:Casino 1244288291
Casino 1244289959:Casino 1244289959
Casino 1244288435:Casino 1244288435
Casino 1244292315:Casino 1244292315
Casino 1244308506:Casino 1244308506
Casino 1244352751:Casino 1244352751
Casino 1250188638:Casino 1250188638
Casino 1250516354:Casino 1250516354
Casino 1250610082:Casino 1250610082
Casino 1250642897:Casino 1250642897


1 comments:
#1: wakeonlan in /etc/network/interfaces is needed
By: sevenever | 2009-05-26 15:11

On Linux system, we should install ethtool and edit /etc/network/interfaces, like this: ----------------------------------------------------- # The primary network interface auto eth0 iface eth0 inet dhcp post-up ethtool -s eth0 wol g post-down ethtool -s eth0 wol g ----------------------------------------------------- the "g" means "Wake on MagicPacket(tm)" that's how we send package. And If you use Debian dist(Ubuntu included), you should edit file /etc/init.d/halt, change the line "NETDOWN=yes" to "NETDOWN=no" to prevent Linux poweroff your NIC while halting, see https://bugs.launchpad.net/debian/+source/sysvinit/+bug/71418 for more infomation.


sevenever@gmail.com
Copyright © 2008. All rights reserved.