Init commit

This commit is contained in:
Obfusu22
2026-06-29 09:01:41 +05:30
commit 479fcb2169
5 changed files with 71 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
Generated
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "woly"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "woly"
version = "0.1.0"
edition = "2024"
[dependencies]
+29
View File
@@ -0,0 +1,29 @@
## Woly
Construct Wake on Lan (WoL) magic packet to power on mini PC via LAN
## Usage
```
woly aa:bb:cc:dd:ee:ff
```
## Magic Packet
Magic packet is constructed as follows
FF x 6; Mac Address x 15
eg.
```
FF FF FF FF FF FF
AA BB CC DD EE FF
AA BB CC DD EE FF
...
```
## Target Destination
The magic packet shall be sent to limited broadcast IP - `255.255.255.255` and the Discard Protocol Port `9`.
While sending it to targeted IP, for eg. 192.168.0.2 bound to desired mac address of the device might work, it is not reliable as sometimes the ARP cache will not be updated by router due to device being in low power mode and will drop this packet.
+28
View File
@@ -0,0 +1,28 @@
use std::env::args;
use std::net::UdpSocket;
fn get_magic_pkt(mac: String) -> [u8; 102] {
let mut mac_bytes = [0u8; 6];
let mut magic_bytes = [0u8; 102];
magic_bytes[..6].fill(0xFF);
for (i, part) in mac.split(':').enumerate() {
mac_bytes[i] = u8::from_str_radix(part, 16).unwrap();
}
for i in 0..16 {
let start = 6 + i * 6;
magic_bytes[start..start + 6].copy_from_slice(&mac_bytes);
}
magic_bytes
}
fn main() {
let mac = args().nth(1).expect("no mac given; Usage woly aa:bb:cc:dd:ee:ff");
let magic_bytes = get_magic_pkt(mac);
let socket = UdpSocket::bind("0.0.0.0:0").expect("couldnt' bind socket");
socket.set_broadcast(true).expect("couldn't set broadcast");
socket.send_to(&magic_bytes, "255.255.255.255:9").expect("couldn't send data");
println!("{:02X?}", magic_bytes);
}