MAC Address Validator & API Payload Generator
Network agents reboot modems by calling custom hardware APIs. These APIs crash if the input parameters (IP Address or MAC Address) are syntactically malformed.
Write a function generate_reboot_payload(raw_mac, raw_ip, command) that:
- Validates the MAC address: supports standard forms separated by colons (e.g.
00:1A:2B:3C:4D:5E) or hyphens (e.g.00-1A-2B-3C-4D-5E), or plain hex (001A2B3C4D5E). Returns a normalized MAC in uppercase with colon dividers. - Validates the IP Address (must be standard IPv4 e.g.
192.168.1.1). - If either is invalid, raises a
ValueErrorwith description details. - Returns a payload dictionary:
{"mac": normalized_mac, "ip": raw_ip, "action": command}.
Example
generate_reboot_payload("00-1a-2b-3c-4d-5e", "192.168.1.100", "reboot")
# Returns: {"mac": "00:1A:2B:3C:4D:5E", "ip": "192.168.1.100", "action": "reboot"}