Changeset 372 for misc/wakeup


Ignore:
Timestamp:
Apr 26, 2012, 6:02:58 PM (13 years ago)
Author:
Rick van der Zwet
Message:

Usefull when playing around with multiple interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/wakeup

    r371 r372  
    77import sys
    88
    9 def wake_on_lan(macaddress):
     9def wake_on_lan(macaddress, broadcast):
    1010    """ Switches on remote computers using WOL. """
    1111
     
    3131    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    3232    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    33     sock.sendto(send_data, ('<broadcast>', 7))
     33    sock.sendto(send_data, (broadcast, 7))
    3434   
    3535
     
    3939                'sb' : '00:13:d4:06:0c:79' }
    4040    if len(sys.argv) == 1:
    41        print "Usage: %s <macaddr|host>" % sys.argv[0]
     41       print "Usage: %s <macaddr|host> [<broadcast>]" % sys.argv[0]
    4242       print ""
    4343       print "Hosts configured: "
     
    4646       sys.exit(64)
    4747
    48     if hostmac.has_key(sys.argv[1]):
    49        wake_on_lan(hostmac[sys.argv[1]])
    50     else:
    51        wake_on_lan(sys.argv[1])
     48    try:
     49      mac = hostmac[sys.argv[1]]
     50    except KeyError: 
     51      mac = sys.argv[1]
     52
     53    try:
     54      broadcast = sys.argv[2]
     55    except IndexError:
     56      broadcast = '<broadcast>'
     57
     58    wake_on_lan(mac, broadcast)
Note: See TracChangeset for help on using the changeset viewer.