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:
17
README.md
17
README.md
@@ -30,22 +30,25 @@ Send a Sleep packet to put a target device to sleep (default port: 9999)
|
|||||||
|
|
||||||
## Arguments
|
## 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]**
|
- `-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]**
|
- `-u, --username`: Username for authentication **[optional for wake, required for sleep]**
|
||||||
- `-p, --password`: Password for authentication **[required]**
|
- `-p, --password`: Password for authentication **[optional for wake, required for sleep]**
|
||||||
- `-H, --host`: Target host address (default: 255.255.255.255 for broadcast)
|
- `-H, --host`: Target host address (default: 255.255.255.255 for broadcast)
|
||||||
- `-P, --port`: Target UDP port (default: 9 for wake, 9999 for sleep)
|
- `-P, --port`: Target UDP port (default: 9 for wake, 9999 for sleep)
|
||||||
|
|
||||||
## Examples
|
## 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
|
```bash
|
||||||
python index.py wake -m AA:BB:CC:DD:EE:FF -u admin -p secret -H 192.168.1.100
|
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
|
```bash
|
||||||
python index.py sleep -m AA:BB:CC:DD:EE:FF -u admin -p secret -H 192.168.1.100 -P 9999
|
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
|
## Notes
|
||||||
|
|
||||||
- The tool sends packets using the UDP protocol.
|
- 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 broadcasting to the target host address.
|
||||||
- The tool supports specifying the target UDP port.
|
- The tool supports specifying the target UDP port.
|
||||||
- Default ports differ between commands: wake uses port 9, sleep uses port 9999.
|
- Default ports differ between commands: wake uses port 9, sleep uses port 9999.
|
||||||
|
|||||||
17
index.py
17
index.py
@@ -104,6 +104,7 @@ def main():
|
|||||||
Examples:
|
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 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 -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(
|
wake_parser.add_argument(
|
||||||
'-u', '--username',
|
'-u', '--username',
|
||||||
required=True,
|
help='Username for authentication (optional)'
|
||||||
help='Username for authentication'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
wake_parser.add_argument(
|
wake_parser.add_argument(
|
||||||
'-p', '--password',
|
'-p', '--password',
|
||||||
required=True,
|
help='Password for authentication (optional)'
|
||||||
help='Password for authentication'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
wake_parser.add_argument(
|
wake_parser.add_argument(
|
||||||
@@ -183,11 +182,21 @@ Examples:
|
|||||||
|
|
||||||
args = parser.parse_args()
|
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
|
# Send the appropriate packet
|
||||||
command_name = "Wake-on-LAN" if args.command == 'wake' else "Sleep"
|
command_name = "Wake-on-LAN" if args.command == 'wake' else "Sleep"
|
||||||
print(f"Sending {command_name} packet to {args.mac}...")
|
print(f"Sending {command_name} packet to {args.mac}...")
|
||||||
print(f"Host: {args.host}:{args.port}")
|
print(f"Host: {args.host}:{args.port}")
|
||||||
|
|
||||||
|
if args.username:
|
||||||
print(f"Username: {args.username}")
|
print(f"Username: {args.username}")
|
||||||
|
else:
|
||||||
|
print("No authentication (anonymous)")
|
||||||
|
|
||||||
success = send_wol_packet(
|
success = send_wol_packet(
|
||||||
mac_address=args.mac,
|
mac_address=args.mac,
|
||||||
|
|||||||
Reference in New Issue
Block a user