feat(wake): Make authentication optional for wake command

- Remove required flag from username/password for wake command
- Add validation to ensure both auth params are provided together
- Update help text and examples to show optional authentication
- Update README documentation to reflect authentication requirements
This commit is contained in:
Björn Benouarets
2025-11-12 12:28:17 +01:00
parent 784ebf24e4
commit 0cf7a0f82c
2 changed files with 24 additions and 12 deletions

View File

@@ -30,22 +30,25 @@ Send a Sleep packet to put a target device to sleep (default port: 9999)
## Arguments
Both commands share the same arguments:
- `-m, --mac`: MAC address of the target device (format: XX:XX:XX:XX:XX:XX or XX-XX-XX-XX-XX-XX) **[required]**
- `-u, --username`: Username for authentication **[required]**
- `-p, --password`: Password for authentication **[required]**
- `-u, --username`: Username for authentication **[optional for wake, required for sleep]**
- `-p, --password`: Password for authentication **[optional for wake, required for sleep]**
- `-H, --host`: Target host address (default: 255.255.255.255 for broadcast)
- `-P, --port`: Target UDP port (default: 9 for wake, 9999 for sleep)
## Examples
Wake up a device:
Wake up a device without authentication:
```bash
python index.py wake -m AA:BB:CC:DD:EE:FF
```
Wake up a device with authentication:
```bash
python index.py wake -m AA:BB:CC:DD:EE:FF -u admin -p secret -H 192.168.1.100
```
Put a device to sleep:
Put a device to sleep (authentication required):
```bash
python index.py sleep -m AA:BB:CC:DD:EE:FF -u admin -p secret -H 192.168.1.100 -P 9999
```
@@ -53,7 +56,7 @@ python index.py sleep -m AA:BB:CC:DD:EE:FF -u admin -p secret -H 192.168.1.100 -
## Notes
- The tool sends packets using the UDP protocol.
- The tool supports authentication using a username and password.
- Authentication is optional for wake commands but required for sleep commands.
- The tool supports broadcasting to the target host address.
- The tool supports specifying the target UDP port.
- Default ports differ between commands: wake uses port 9, sleep uses port 9999.

View File

@@ -104,6 +104,7 @@ def main():
Examples:
%(prog)s wake -m AA:BB:CC:DD:EE:FF -u admin -p secret
%(prog)s wake -m AA-BB-CC-DD-EE-FF -u user -p pass -H 192.168.1.100
%(prog)s wake -m AA:BB:CC:DD:EE:FF
"""
)
@@ -115,14 +116,12 @@ Examples:
wake_parser.add_argument(
'-u', '--username',
required=True,
help='Username for authentication'
help='Username for authentication (optional)'
)
wake_parser.add_argument(
'-p', '--password',
required=True,
help='Password for authentication'
help='Password for authentication (optional)'
)
wake_parser.add_argument(
@@ -183,11 +182,21 @@ Examples:
args = parser.parse_args()
# For wake command, check if authentication is provided
if args.command == 'wake':
if (args.username and not args.password) or (args.password and not args.username):
print("Error: Both username and password must be provided for authentication.", file=sys.stderr)
return 1
# Send the appropriate packet
command_name = "Wake-on-LAN" if args.command == 'wake' else "Sleep"
print(f"Sending {command_name} packet to {args.mac}...")
print(f"Host: {args.host}:{args.port}")
print(f"Username: {args.username}")
if args.username:
print(f"Username: {args.username}")
else:
print("No authentication (anonymous)")
success = send_wol_packet(
mac_address=args.mac,