wake_on_lan 1.1.0 copy "wake_on_lan: ^1.1.0" to clipboard
wake_on_lan: ^1.1.0 copied to clipboard

outdated

Send wake on LAN magic packets to devices on your local network.

wake_on_lan #

Pubdev Code Coverage License

Dart library package to easily send Wake-on-LAN magic packets to devices on your local network.

Getting Started #

wake_on_lan has three core classes for functionality, IPv4Address, MACAddress, and WakeOnLAN. All classes are exported in the main file, to import:

import 'package:wake_on_lan:wake_on_lan.dart';

Create an IPv4 Address

IPv4Address is a helper class to ensure that your IPv4 address has been formatted correctly.

The class has a static function, validate(String address) which allows easy validation that an IPv4 address string is correctly formatted.

Create an IPv4Address object by using the factory IPv4Address.from(address) where address is a string representation of the address. The factory will call the validation function mentioned above, but will throw a FormatException on a poorly constructed string, so it is recommended to validate it first.

String address = '192.168.1.1';
if(IPv4Address.validate(address)) {
    IPv4Address ipv4 = IPv4Address.from(address);
    //Continue execution
} else {
    // Handle invalid address case
}

Create MAC Address

MACAddress is a helper class to ensure that your MAC address has been formatted correctly.

The class has a static function, validate(String address) which allows easy validation that an MAC address string is correctly formatted.

The MAC address must be delimited by colons (:) between each hexidecimal octet.

Create a MACAddress object by using the factory MACAddress.from(address) where address is a string representation of the address. The factory will call the validation function mentioned above, but will throw a FormatException on a poorly constructed string, so it is recommended to validate it first.

String address = 'A4:83:E7:0D:7F:4F';
if(MACAddress.validate(address)) {
    MACAddress mac = MACAddress.from(address);
    //Continue execution
} else {
    // Handle invalid address case
}

Sending Wake-on-LAN Packet

WakeOnLAN is the class to handle sending the actual wake-on-LAN magic packet to your network.

Create a WakeOnLAN object by using the factory WakeOnLAN.from(ipv4, mac, { port }) where ipv4 is an IPv4Address object, mac is a MACAddress object, and port is an optional integer parameter for which port the packet should be sent over (defaulted to the specification standard port, 9).

Once created, call the function wake() on the WakeOnLAN object to send the packet.

String mac = 'A4:83:E7:0D:7F:4F';
String ipv4 = '192.168.1.255';
if(MACAddress.validate(mac) && IPv4Address.validate(ipv4)) {
    MACAddress macAddress = MACAddress.from(mac);
    IPv4Address ipv4Address = IPv4Address.from(ipv4);
    WakeOnLAN wol = WakeOnLAN.from(ipv4Address, macAddress, port: 1234);
    await wol.wake().then(() => print('sent'));
}

Notes #

Because wake-on-LAN packets are sent over UDP, beyond the successful creation of a datagram socket and sending the data over the network, there is no way to confirm that the machine has been awoken beyond pinging the machine after waking it (This functionality is not implemented in this package). This is because of the nature of UDP sockets which do not need to establish the connection for the data to be sent.

14
likes
0
pub points
68%
popularity

Publisher

verified publisherjagandeepbrar.io

Send wake on LAN magic packets to devices on your local network.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

convert

More

Packages that depend on wake_on_lan