我为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 的快照。