0

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. enter image description here

Rao
  • 2,902
  • 14
  • 52
  • 70

1 Answers1

0

Two things you can check.

  1. You're trying to send a broadcast packet from one subnet to another. This implies a network device inbetween the two, probably a router. Routers are normally configured to disallow broadcast packets between their managed subnets to avoid a broadcast storm.

    If this is your own experimental network on which you own the routers then you'll be able to go in and change the router configuration yourself.

  2. If you've done (1) and it still doesn't work then look at the TTL of the packets you're generating. If they're being sent with a TTL of one (often the default for broadcast/multicast for safety reasons) then you'll need to increase it by one for each network device that you must traverse along the way because each device decrements the TTL and drops the packet if zero is reached.

Community
  • 1
  • 1
Andy Brown
  • 11,766
  • 2
  • 42
  • 61
  • i tried the same scenario with 3rd party tool from EMCO from http://emcosoftware.com/wake-on-lan and it could able to wake my system C from system B. So i think your suggestion of point 1 is fine. So waht can i do further. how to increase TTL from python – Rao Mar 04 '15 at 02:23
  • It could be the `IP_TTL` option to `setsockopt`. Try to capture your broadcast packets on another PC on the same subnet using Wireshark and inspect the IP header. – Andy Brown Mar 04 '15 at 09:37
  • Added snapshot of received packet on same subnet, let me what can i do further. what would be IP header you are talking about. – Rao Mar 17 '15 at 04:19