I developed an application to wakeOnLan (WOL) and is working fine with in same series of IP addresses.
My problem is i am not able to wakeOnLan where systems are on on other series of IP address on Same Network.
For EX:
My system A is having IP 172.16.46.76,
I am able to wake any system C with Ip Address 172.16.46.13, and also able to wake on lan any system with in the range of 172.16.46.1 to 172.16.45.254 using BroadCast address 1721.16.46.255
But when i run same application from other system B having IP 172.16.51.26, I am not able to wakeOnLan systems C with IP Address 172.16.46.13
I checked using WakeOnLan monitor to confirm if system C is receiving magic packet. And it is receiving from system A but not from system B. I could able to ping system C from both system A and system B
Can any one suggest me solution where is am doing wrong. I code is give below for your reference.
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')
A snapshot from Wake On Lan Monitor.