Skip to content

Commit

Permalink
Merge pull request #1 from mszeu/devel
Browse files Browse the repository at this point in the history
Devel to main
  • Loading branch information
mszeu authored Jun 8, 2022
2 parents 4165f2d + 790ad0e commit be0fa62
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ Wake-on-Lan magic packet generator
**wakeup**
## VERSION

**1.0**
**1.1**

## DESCRIPTION
**wakeup** is a simple python script that generates and sends a Wake-on-Lan magic packet to the specified MAC address
**wakeup** is a simple python script that generates and sends a Wake-on-Lan magic packet to the specified MAC address.

The script is given **AS IS** and it is under the **AGPL Aferro license 3.0**.

For more information about the license terms please refer tot the **LICENSE** file distributed with the project.
## USAGE

**wakeup.py** **MACAddress** [**--port** port]
**wakeup.py** **MACAddress** [**--port** port] [**--times** times] [**--interval** interval]
- **MACAddress**: is the MAC address of the appliance to wake up (e.g.: *0011223344AF*)
- **--port**: the destination of the magic packet. If is not specified the default is 7

## EXAMPLE
- **--port**: the destination of the magic packet. If is not specified the default is 7.
- **--times**: times to send the magic packet. If it is not specified the default is 1.
- **--interval**: interval, in seconds, between packets. If it is not specified the default is 0.
## EXAMPLES

**wakeup.py** 0011223344AF **--port** 9

**wakeup.py** 0011223344AF **--port** 9 **--interval** 2 **--times** 10

**wakeup.py** 0011223344AF

## REQUIREMENTS
The program requires **Python 3**. It was tested and developed under **Python 3.10**

Expand Down
25 changes: 21 additions & 4 deletions wakeup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import argparse
import socket
import time


def wol(lunaMacAddress: bytes, port: int):
Expand All @@ -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(
Expand All @@ -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")

0 comments on commit be0fa62

Please sign in to comment.