Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the code to work on newer versions of python (3.5+) fixes #1 #2

Merged
merged 2 commits into from
Jul 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions wol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Based on wol.py from http://code.activestate.com/recipes/358449-wake-on-lan/
# Amended to use configuration file and hostnames
#
#
# Copyright (C) Fadly Tabrani, B Tasker
#
# Released under the PSF License See http://docs.python.org/2/license.html
Expand All @@ -14,7 +14,7 @@
import struct
import os
import sys
import ConfigParser
import configparser


myconfig = {}
Expand All @@ -38,14 +38,14 @@ def wake_on_lan(host):
macaddress = macaddress.replace(sep, '')
else:
raise ValueError('Incorrect MAC address format')

# Pad the synchronization stream.
data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
send_data = ''
send_data = b''

# Split up the hex values and pack.
for i in range(0, len(data), 2):
send_data = ''.join([send_data,
send_data = b''.join([send_data,
struct.pack('B', int(data[i: i + 2], 16))])

# Broadcast it to the LAN.
Expand All @@ -61,7 +61,7 @@ def loadConfig():
"""
global mydir
global myconfig
Config = ConfigParser.ConfigParser()
Config = configparser.ConfigParser()
Config.read(mydir+"/.wol_config.ini")
sections = Config.sections()
dict1 = {}
Expand All @@ -79,31 +79,28 @@ def loadConfig():
return myconfig # Useful for testing

def usage():
print 'Usage: wol.py [hostname]'
print('Usage: wol.py [hostname]')



if __name__ == '__main__':
mydir = os.path.dirname(os.path.abspath(__file__))
conf = loadConfig()

try:
# Use macaddresses with any seperators.

if sys.argv[1] == 'list':
print 'Configured Hosts:'
for i in conf:
if i != 'General':
print '\t',i
print '\n'
else:

if not wake_on_lan(sys.argv[1]):
print 'Invalid Hostname specified'
else:
print 'Magic packet should be winging its way'
except:
usage()
mydir = os.path.dirname(os.path.abspath(__file__))
conf = loadConfig()
try:
# Use macaddresses with any seperators.
if sys.argv[1] == 'list':
print('Configured Hosts:')
for i in conf:
if i != 'General':
print('\t',i)
print('\n')
else:
if not wake_on_lan(sys.argv[1]):
print('Invalid Hostname specified')
else:
print('Magic packet should be winging its way')
except:
usage()



Expand Down