English 中文(简体)
WOL 来自广域网外
原标题:WOL from outside WAN

A while ago, I wrote [with some help from Google] a small WOL script to switch on the computers in my network. Here is the script:

exec /usr/bin/python -x "$0" "$@"
#
node_lst = [
         srv1 0a:1b:8c:0d:2e:7f ,
         srv2 0A-0B-4C-8D-CE:3F ,
]
#
import os,sys,string,commands
import struct, socket
import re,random

retval = 0

mac_addr = "mac_addr.txt"
X =  ([a-zA-Z0-9]{2}[:|-|.]?){5}[a-zA-Z0-9]{2} 
S = re.compile(r s+ )

mmap = {}

## First argument  None  in str.translate is new in 2.6. 
## Previously, it was a string of 256 characters 
if sys.version_info < (2, 6):
    f1_arg =   .join(chr(i) for i in xrange(256))
else:
    f1_arg = None

## broadcast address
sysOS = "uname -s"
BSD = "ifconfig | grep -w broadcast | cut -d  -f 6"
LNX = "ip -o addr show | grep -w inet | grep -e eth | cut -d  -f 9"
#
if commands.getoutput(sysOS) == "Linux":
    bCast = commands.getoutput(LNX)
elif commands.getoutput(sysOS) == "Darwin":
    bCast = commands.getoutput(BSD)
else:
    print "System not supported!!"
    sys_exit()

def WakeOnLan(mac_address):

    ## Building the Wake-On-LAN "Magic Packet"...
    ## Pad the synchronization stream.
    data =   .join([ FFFFFFFFFFFF , mac_address * 20])
    msg =   

    ## Split up the hex values and pack.
    for i in range(0, len(data), 2):
        msg =   .join([msg, struct.pack( B , int(data[i: i + 2], 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, (bCast, 9))
    s.close()

def sys_exit():
    sys.stdout.flush()
    sys.exit(1)

## check if hostname is provided
if len(sys.argv) != 2:
    print "Usage: %s <hostname>" % sys.argv[0]
    sys_exit()

for i in node_lst:
    # strip off everything from first "#" [if] found
    i = i.split( # ,1)[0]
    if not re.search(X, i):
        continue

    h = S.split(i,1)[0]                 ## host name
    m = S.split(i,1)[-1]                ## MAC address
    mmap[h] = m.strip( 	|" " )

for j, k in mmap.iteritems():
    if sys.argv[1] == j:
        if not re.search(X.replace( zA-Z , fA-F ), k):
            print "Invalid MAC address [",k,"]; nothing to do!!"
            sys_exit()
        else:
            WakeOnLan(k.translate(f1_arg, :.- ))
            print "WOL request has been sent to %s [%s]" % (j,k)
            break
else:
    print "Host [%s] doesn t exist!!" % sys.argv[1]
    sys_exit()

那些在我家网络(或局域网)内刚开课。 我怎么能改变文字,使之在我的局外发挥作用? 任何想法或建议? !

问题回答

之所以无法做到这一点,是因为WOL包裹是广播包裹(因为你可以知道谁也发送)。 家庭路由器,特别是ISP/Network路由器丢弃所有广播包裹,因为每当你管理这本书时,整个互联网上的所有计算机都会接受你的包裹,这将造成相当一部分cl。

What you of course can do is write a small application that is on a computer that is running inside the WAN in which you wish to turn on all computers, and then have that application send a WOL packet. However this would require a computer with internet access to be turned on at all times.

Configure your router to forward packets on a selection of 10 non-sequential ports to a machine on your LAN.

制定一些基于GMT 时+一 has的计划,以产生港口触发序列。

在该网络的指挥箱上有一个 p子节目(使用剪辑)聆听了一系列yn子。

聆听员守则将类似于以下 t:

sudo tcpdump -ni eth0  tcp[tcpflags] & (tcp-syn) !=0 

哪里只捕获了yn。

你的方案只是坐在那里,等待正确的顺序。 当收到顺序时,它使用你的邮资。

Done。

如果你不希望开放港口,那么你的文字就能够污染一个遥远的网站,等待变化。 或通过电子邮件收听电子邮件。

Taking your idea further, you could do fancy stuff like turn on your lights or boot up the TV.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签