Update wol.py
The use of regular expressions to remove the not usable characters in mac is more elegant and flexible option.
--- a/wol.py
+++ b/wol.py
@@ -15,6 +15,7 @@
import os
import sys
import configparser
+import re
myconfig = {}
@@ -32,12 +33,15 @@
# Check macaddress format and try to compensate.
if len(macaddress) == 12:
- pass
- elif len(macaddress) == 12 + 5:
- sep = macaddress[2]
- macaddress = macaddress.replace(sep, '')
+ pass
else:
- raise ValueError('Incorrect MAC address format')
+ # Use regular expression to extract not usable chars
+ macaddress = re.sub('[^A-F0-9]', '', macaddress,flags=re.IGNORECASE)
+ # Re-check the value
+ if len(macaddress) == 12:
+ pass
+ else:
+ raise ValueError('Incorrect MAC address format')
# Pad the synchronization stream.
data = ''.join(['FFFFFFFFFFFF', macaddress * 20])