-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mszeu/devel
Devel to main
- Loading branch information
Showing
3 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
import argparse | ||
import socket | ||
import time | ||
|
||
|
||
def wol(lunaMacAddress: bytes, port: int): | ||
|
@@ -15,10 +16,12 @@ def wol(lunaMacAddress: bytes, port: int): | |
s.sendto(magic, ('<broadcast>', port)) | ||
print("packet sent to:", lunaMacAddress.hex(), "port:", port) | ||
print("Magic packet:", magic.hex()) | ||
print() | ||
|
||
|
||
if __name__ == '__main__': | ||
print("wakeup - by Marco S. Zuppone - [email protected] - https://msz.eu") | ||
VERSION = "1.1" | ||
print("wakeup - by Marco S. Zuppone - [email protected] - https://msz.eu - version", VERSION) | ||
print("Program licensed under GNU AFFERO GENERAL PUBLIC LICENSE version 3") | ||
print("") | ||
parser = argparse.ArgumentParser( | ||
|
@@ -27,13 +30,27 @@ def wol(lunaMacAddress: bytes, port: int): | |
"author at [email protected]") | ||
parser.add_argument("MACAddress", type=str, | ||
help="The MAC Address of the Ethernet device to wake. Example: 0011223344AA") | ||
parser.add_argument("--port", type=int, default=7, help="The port where to send the magic packet") | ||
parser.add_argument("--port", type=int, default=7, help="The port where to send the magic packet", | ||
) | ||
parser.add_argument("--times", type=int, default=1, help="times to send the magic packet") | ||
parser.add_argument("--interval", type=int, default=0, | ||
help="interval, in seconds, between packets") | ||
args = parser.parse_args() | ||
chars = set('0123456789abcdedABCDEF') | ||
if len(args.MACAddress) != 12 and not (all((c in chars) for c in args.MACAddress)): | ||
print("the MAC Address needs to be hexadecimal without spaces or signs between one byte and the other and the " | ||
"bytes need to be 6") | ||
exit() | ||
if args.times < 1: | ||
args.times = 1 | ||
if args.interval < 0: | ||
args.interval = 0 | ||
if args.port < 0 or args.port > 65535: | ||
print('The port need to be between 0 and 65535') | ||
exit() | ||
# pass to wol the mac address of the ethernet port of the appliance to wakeup | ||
wol(bytearray.fromhex(args.MACAddress), args.port) | ||
|
||
for x in range(args.times): | ||
wol(bytearray.fromhex(args.MACAddress), args.port) | ||
if x + 1 != args.times: | ||
time.sleep(args.interval) | ||
print("The End") |