0

我为wakeOnLan (WOL) 开发了一个应用程序,并且在同一系列IP 地址中运行良好。

我的问题是我无法唤醒系统位于同一网络上其他系列 IP 地址上的系统。

对于 EX:

我的系统 A的 IP 为 172.16.46.76,

我可以使用 IP 地址 172.16.46.13 唤醒任何系统 C,还可以使用广播地址 1721.16.46.255 在 172.16.46.1 到 172.16.45.254 范围内唤醒任何系统

但是当我从其他具有 IP 172.16.51.26 的系统 B运行相同的应用程序时,我无法唤醒具有 IP 地址 172.16.46.13的系统 C

我使用 WakeOnLan 监视器检查以确认系统 C是否正在接收魔术包。它是从系统 A接收,而不是从系统 B接收。我可以从系统 A系统 B ping 系统 C

任何人都可以建议我解决哪里做错了。我的代码如下供您参考。

import sys, struct, socket

# Configuration variables
broadcast = ['172.16.46.255','172.16.51.255']
wol_port = 9

known_computers = {
    'mercury'    : '00:1C:55:35:12:BF',
    'venus'      : '00:1d:39:55:5c:df',
    'earth'      : '00:10:60:15:97:fb',
    }

def WakeOnLan(ethernet_address):

    # Construct 6 byte hardware address
    add_oct = ethernet_address.split(':')
    if len(add_oct) != 6:
        print "\n*** Illegal MAC address\n"
        print "MAC should be written as 00:11:22:33:44:55\n"
        return
    hwa = struct.pack('BBBBBB', int(add_oct[0],16),
        int(add_oct[1],16),
        int(add_oct[2],16),
        int(add_oct[3],16),
        int(add_oct[4],16),
        int(add_oct[5],16))

    # Build magic packet

    msg = '\xff' * 6 + hwa * 16

    # Send packet to broadcast address using UDP port 9
    print msg
    soc = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    soc.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
    for i in broadcast:
        soc.sendto(msg,(i,wol_port))
    soc.close()

def wol(*argv):

    if len(argv) == 0:
        print "\n*** No computer given to power up\n"
        print "Use: 'wol (computername)' or 'wol (00:11:22:33:44:55)'"
    else:
        for i in argv:
            if i[0] != '/':
                if ":" in i:
                    # Wake up using MAC address
                    print 'waking using MAC %s' % i
                    WakeOnLan(i)
                else:
                    # Wake up known computers
                    if i in known_computers:
                        WakeOnLan(known_computers[i])
                    else:
                        print "\n*** Unknown computer " + i + "\n"
                        quit()

        if len(argv) == 1:
            print "\nDone! The computer should be up and running in a short while."
        else:
            print "\nDone! The computers should be up and running in a short while."
        print

wol('xx:xx:xx:xx:xx:xx')

来自 Wake On Lan Monitor 的快照。 在此处输入图像描述

4

1 回答 1

0

你可以检查两件事。

  1. 您正在尝试将广播数据包从一个子网发送到另一个子网。这意味着两者之间有一个网络设备,可能是路由器。路由器通常配置为不允许在其管理的子网之间广播数据包以避免广播风暴

    如果这是您拥有路由器的您自己的实验网络,那么您将能够自己进入并更改路由器配置。

  2. 如果您已完成 (1) 并且仍然无法正常工作,请查看您正在生成的数据包的 TTL。如果它们以 1 的 TTL 发送(出于安全原因,通常是广播/多播的默认值),那么您需要为每个必须遍历的网络设备将其增加 1,因为每个设备都会递减 TTL如果达到零,则丢弃数据包。

于 2015-03-03T14:29:28.813 回答