### Install PyWakeOnLan Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/readme.md Install the pywakeonlan package using pip. Ensure you have Python 3.x installed. ```bash pip install wakeonlan ``` -------------------------------- ### main() Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/index.md Entry point for the standalone script execution. ```APIDOC ## main() ### Description Main function used when running pywakeonlan as a standalone script. ``` -------------------------------- ### Use the Command Line Interface Source: https://context7.com/remcohaszing/pywakeonlan/llms.txt Execute the wakeonlan command from the terminal to wake up machines. Supports various flags for IP, port, and interface configuration. ```bash # Wake up a single computer wakeonlan ff:ff:ff:ff:ff:ff # Wake up multiple computers wakeonlan ff:ff:ff:ff:ff:ff 00:11:22:33:44:55 aa:bb:cc:dd:ee:ff # Specify a target IP address (for subnet-directed broadcast or remote host) wakeonlan -i 192.168.1.255 ff:ff:ff:ff:ff:ff # Use a custom port wakeonlan -p 7 ff:ff:ff:ff:ff:ff # Route through a specific network interface wakeonlan -n 192.168.0.2 ff:ff:ff:ff:ff:ff # Use IPv6 instead of IPv4 wakeonlan -6 -i fc00::1 ff:ff:ff:ff:ff:ff # Combine multiple options wakeonlan -i 192.168.1.255 -p 9 -n 192.168.1.100 aa:bb:cc:dd:ee:ff # Show help wakeonlan --help ``` -------------------------------- ### Command Line Interface (CLI) Source: https://context7.com/remcohaszing/pywakeonlan/llms.txt Provides a standalone CLI for waking computers from the terminal using the `wakeonlan` command. ```APIDOC ## Command Line Interface (main) ### Description Provides a standalone CLI for waking computers from the terminal. The `wakeonlan` command is installed automatically with the package and supports all the same options as the Python API. ### Usage `wakeonlan [OPTIONS] MAC_ADDRESS [MAC_ADDRESS ...]` ### Options - `-i, --ip-address IP_ADDRESS` : Specify the target IP address (for subnet-directed broadcast or remote host). - `-p, --port PORT` : Use a custom port. - `-n, --interface INTERFACE` : Route through a specific network interface. - `-6, --ipv6` : Use IPv6 instead of IPv4. - `--help` : Show help message. ### Examples ```bash # Wake up a single computer wakeonlan ff:ff:ff:ff:ff:ff # Wake up multiple computers wakeonlan ff:ff:ff:ff:ff:ff 00:11:22:33:44:55 aa:bb:cc:dd:ee:ff # Specify a target IP address wakeonlan -i 192.168.1.255 ff:ff:ff:ff:ff:ff # Use a custom port wakeonlan -p 7 ff:ff:ff:ff:ff:ff # Route through a specific network interface wakeonlan -n 192.168.0.2 ff:ff:ff:ff:ff:ff # Use IPv6 instead of IPv4 wakeonlan -6 -i fc00::1 ff:ff:ff:ff:ff:ff # Combine multiple options wakeonlan -i 192.168.1.255 -p 9 -n 192.168.1.100 aa:bb:cc:dd:ee:ff # Show help wakeonlan --help ``` ### Programmatic CLI Invocation ```python from wakeonlan import main # Equivalent to: wakeonlan 00:11:22:33:44:55 -i host.example -p 1337 main(['00:11:22:33:44:55', '-i', 'host.example', '-p', '1337']) # With interface binding main(['00:11:22:33:44:55', '-i', 'host.example', '-p', '1337', '-n', '192.168.0.2']) # With IPv6 flag main(['00:11:22:33:44:55', '-i', 'host.example', '-p', '1337', '-6']) ``` ### Response The CLI does not produce structured output beyond standard console messages or errors. ``` -------------------------------- ### Wake Computer with Custom IP and Port Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/readme.md Send a magic packet to a specified IP address and port. Port forwarding on the target host is required. The default IP is 255.255.255.255 and the default port is 9. ```python send_magic_packet('ff.ff.ff.ff.ff.ff', ip_address='example.com', port=1337) ``` -------------------------------- ### Wake Computer via Specific Network Interface Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/readme.md Specify a network interface to route the magic packet through. This is useful in multi-homed systems. ```python send_magic_packet('ff.ff.ff.ff.ff.ff', interface='192.168.0.2') ``` -------------------------------- ### Import send_magic_packet Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/readme.md Import the necessary function from the wakeonlan module to send magic packets. ```python from wakeonlan import send_magic_packet ``` -------------------------------- ### Wake Multiple Computers Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/readme.md Send magic packets to multiple computers simultaneously by providing their MAC addresses as separate arguments. ```python send_magic_packet('ff.ff.ff.ff.ff.ff', '00-00-00-00-00-00', 'FFFFFFFFFFFF') ``` -------------------------------- ### Create Magic Packet Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/apidocs.md Generates a magic packet from a given MAC address. This packet can then be sent to wake up a computer. ```APIDOC ## create_magic_packet ### Description Create a magic packet. A magic packet is a packet that can be used with the for wake on lan protocol to wake up a computer. The packet is constructed from the mac address given as a parameter. ### Parameters #### Path Parameters - **macaddress** (str) - Required - The MAC address that should be parsed into a magic packet. ### Response #### Success Response (200) - **bytes** - The generated magic packet. ``` -------------------------------- ### Send Magic Packets Programmatically Source: https://context7.com/remcohaszing/pywakeonlan/llms.txt Use send_magic_packet to wake up computers. Supports multiple MAC formats, custom IP addresses, ports, and interface binding. ```python from wakeonlan import send_magic_packet import socket # Wake up a single computer using default broadcast (255.255.255.255:9) send_magic_packet('ff:ff:ff:ff:ff:ff') # Wake up multiple computers at once with different MAC formats send_magic_packet( 'ff:ff:ff:ff:ff:ff', # colon-separated '00-00-00-00-00-00', # hyphen-separated 'FFFFFFFFFFFF' # no separators ) # Wake up a computer through an external host with port forwarding send_magic_packet( 'aa:bb:cc:dd:ee:ff', ip_address='example.com', port=9 ) # Route the magic packet through a specific network interface send_magic_packet( 'aa:bb:cc:dd:ee:ff', interface='192.168.0.2' ) # Use IPv6 addressing explicitly send_magic_packet( 'aa:bb:cc:dd:ee:ff', ip_address='fc00::1', port=9, address_family=socket.AF_INET6 ) # Combined: specific host, port, and interface send_magic_packet( '01:23:45:67:89:ab', '00:11:22:33:44:55', ip_address='192.168.1.255', port=7, interface='192.168.1.100' ) ``` -------------------------------- ### Invoke CLI Programmatically Source: https://context7.com/remcohaszing/pywakeonlan/llms.txt Use the main function to invoke the CLI logic directly from Python code. ```python # Programmatic CLI invocation via main() from wakeonlan import main # Equivalent to: wakeonlan 00:11:22:33:44:55 -i host.example -p 1337 main(['00:11:22:33:44:55', '-i', 'host.example', '-p', '1337']) # With interface binding main(['00:11:22:33:44:55', '-i', 'host.example', '-p', '1337', '-n', '192.168.0.2']) # With IPv6 flag main(['00:11:22:33:44:55', '-i', 'host.example', '-p', '1337', '-6']) ``` -------------------------------- ### Send Magic Packet Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/apidocs.md Wakes up computers by sending magic packets to their MAC addresses. Supports specifying IP address, port, network interface, and address family. ```APIDOC ## send_magic_packet ### Description Wake up computers having any of the given mac addresses. Wake on lan must be enabled on the host device. ### Method POST ### Endpoint /wakeonlan ### Parameters #### Path Parameters - **macs** (str) - Required - One or more MAC addresses of machines to wake. #### Query Parameters - **ip_address** (str) - Optional - The IP address of the host to send the magic packet to. Defaults to '255.255.255.255'. - **port** (int) - Optional - The port of the host to send the magic packet to. Defaults to 9. - **interface** (str) - Optional - The IP address of the network adapter to route the magic packet through. - **address_family** (AddressFamily) - Optional - The address family of the IP address to initiate connection with. When not specified, chosen automatically between IPv4 and IPv6. ### Response #### Success Response (200) - **None** - Indicates the operation was successful. ``` -------------------------------- ### WakeOnLan Command-Line Script Usage Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/readme.md The wakeonlan script can be used from the command line to wake up computers. It accepts MAC addresses and various options for IP, port, and interface. ```bash usage: wakeonlan [-h] [-6] [-i IP] [-p PORT] [-n INTERFACE] mac address [mac address ...] Wake one or more computers using the wake on lan protocol. positional arguments: mac address The mac addresses of the computers you are trying to wake. options: -h, --help show this help message and exit -6, --ipv6 To indicate if ipv6 should be used by default instead of ipv4. (default: False) -i IP, --ip IP The ip address of the host to send the magic packet to. (default: 255.255.255.255) -p PORT, --port PORT The port of the host to send the magic packet to. (default: 9) -n INTERFACE, --interface INTERFACE The ip address of the network adapter to route the magic packet through. (default: None) ``` -------------------------------- ### Send Magic Packet - Single MAC Source: https://github.com/remcohaszing/pywakeonlan/blob/main/README.rst Wake up a single computer by providing its MAC address. The MAC address can be formatted in various ways. ```python from wakeonlan import send_magic_packet send_magic_packet('ff.ff.ff.ff.ff.ff') ``` -------------------------------- ### Wake Single Computer Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/readme.md Send a magic packet to a single computer using its MAC address. The MAC address can be formatted in various ways. ```python send_magic_packet('ff.ff.ff.ff.ff.ff') ``` -------------------------------- ### Create Magic Packets Manually Source: https://context7.com/remcohaszing/pywakeonlan/llms.txt Use create_magic_packet to generate the byte sequence for a magic packet without sending it. This allows for custom socket handling or inspection. ```python from wakeonlan import create_magic_packet # Create magic packet for a MAC address (returns bytes) packet = create_magic_packet('01:23:45:67:89:ab') print(f"Packet length: {len(packet)} bytes") # Output: Packet length: 102 bytes print(f"Packet hex: {packet.hex()}") # Supports multiple MAC formats packet_colon = create_magic_packet('01:23:45:67:89:ab') packet_hyphen = create_magic_packet('01-23-45-67-89-ab') packet_dot = create_magic_packet('0123.4567.89ab') packet_plain = create_magic_packet('0123456789ab') # All formats produce identical packets assert packet_colon == packet_hyphen == packet_dot == packet_plain # Handle invalid MAC addresses try: create_magic_packet('invalid-mac') except ValueError as e: print(f"Error: {e}") # Output: Error: Incorrect MAC address format # Manual socket transmission example import socket packet = create_magic_packet('aa:bb:cc:dd:ee:ff') with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) sock.sendto(packet, ('255.255.255.255', 9)) ``` -------------------------------- ### create_magic_packet API Source: https://context7.com/remcohaszing/pywakeonlan/llms.txt Creates a magic packet byte sequence from a MAC address without sending it. Useful for inspection, logging, or custom transmission. ```APIDOC ## create_magic_packet ### Description Creates a magic packet byte sequence from a MAC address without sending it. Useful when you need to inspect, log, or manually transmit the packet through custom socket handling. ### Method `create_magic_packet` ### Parameters - **mac_address** (str) - The MAC address to create the magic packet for. Supports colon-separated, hyphen-separated, dot-separated, or no separators. ### Request Example ```python from wakeonlan import create_magic_packet import socket # Create magic packet for a MAC address (returns bytes) packet = create_magic_packet('01:23:45:67:89:ab') print(f"Packet length: {len(packet)} bytes") print(f"Packet hex: {packet.hex()}") # Supports multiple MAC formats packet_colon = create_magic_packet('01:23:45:67:89:ab') packet_hyphen = create_magic_packet('01-23-45-67-89-ab') packet_dot = create_magic_packet('0123.4567.89ab') packet_plain = create_magic_packet('0123456789ab') # All formats produce identical packets assert packet_colon == packet_hyphen == packet_dot == packet_plain # Handle invalid MAC addresses try: create_magic_packet('invalid-mac') except ValueError as e: print(f"Error: {e}") # Manual socket transmission example packet = create_magic_packet('aa:bb:cc:dd:ee:ff') with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) sock.sendto(packet, ('255.255.255.255', 9)) ``` ### Response - **packet** (bytes) - The magic packet byte sequence. ``` -------------------------------- ### send_magic_packet API Source: https://context7.com/remcohaszing/pywakeonlan/llms.txt Sends Wake-on-LAN magic packets to wake up one or more computers by their MAC addresses. Supports broadcast, specific hosts, custom ports, and network interface binding. ```APIDOC ## send_magic_packet ### Description Sends Wake-on-LAN magic packets to wake up one or more computers by their MAC addresses. This is the primary function for programmatic usage and supports broadcast to local network or specific hosts with optional port forwarding. ### Method `send_magic_packet` ### Parameters - `*mac_addresses` (str) - Variable number of MAC addresses to wake up. Supports colon-separated, hyphen-separated, dot-separated, or no separators. - `ip_address` (str, optional) - The target IP address or hostname. Defaults to broadcast address (255.255.255.255) for IPv4 or link-local for IPv6. - `port` (int, optional) - The target port number. Defaults to 9. - `interface` (str, optional) - The network interface to use for sending the packet (e.g., '192.168.0.2'). - `address_family` (int, optional) - The address family to use (e.g., `socket.AF_INET` or `socket.AF_INET6`). Defaults to `socket.AF_INET`. ### Request Example ```python from wakeonlan import send_magic_packet import socket # Wake up a single computer using default broadcast (255.255.255.255:9) send_magic_packet('ff:ff:ff:ff:ff:ff') # Wake up multiple computers at once with different MAC formats send_magic_packet( 'ff:ff:ff:ff:ff:ff', '00-00-00-00-00-00', 'FFFFFFFFFFFF' ) # Wake up a computer through an external host with port forwarding send_magic_packet( 'aa:bb:cc:dd:ee:ff', ip_address='example.com', port=9 ) # Route the magic packet through a specific network interface send_magic_packet( 'aa:bb:cc:dd:ee:ff', interface='192.168.0.2' ) # Use IPv6 addressing explicitly send_magic_packet( 'aa:bb:cc:dd:ee:ff', ip_address='fc00::1', port=9, address_family=socket.AF_INET6 ) # Combined: specific host, port, and interface send_magic_packet( '01:23:45:67:89:ab', '00:11:22:33:44:55', ip_address='192.168.1.255', port=7, interface='192.168.1.100' ) ``` ### Response This function does not return a value upon successful execution. Errors are raised as exceptions. ``` -------------------------------- ### send_magic_packet() Source: https://github.com/remcohaszing/pywakeonlan/blob/main/docs/index.md Sends a magic packet to the specified MAC address. ```APIDOC ## send_magic_packet(macaddress, ip_address='255.255.255.255', port=9) ### Description Sends a magic packet to the specified MAC address over the network. ### Parameters - **macaddress** (str) - Required - The MAC address of the device to wake. - **ip_address** (str) - Optional - The broadcast IP address to send the packet to. Defaults to '255.255.255.255'. - **port** (int) - Optional - The UDP port to send the packet to. Defaults to 9. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.