i blame the router

This commit is contained in:
ldlda
2025-08-21 08:23:52 +07:00 Unverified
parent a76ecdd5c5
commit f3433ed276
4 changed files with 162 additions and 42 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-none-eabi-gcc"
# advices from gpt5
# advices from gpt5rustup target add armv7-unknown-linux-musleabihf
Generated
+102
View File
@@ -110,6 +110,43 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
[[package]]
name = "color-eyre"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5920befb47832a6d61ee3a3a846565cfa39b331331e68a3b1d1116630f2f26d"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b88ea9df13354b55bc7234ebcce36e6ef896aca2e42a15de9e10edce01b427"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "eyre"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "fnv"
version = "1.0.7"
@@ -247,6 +284,12 @@ dependencies = [
"tower-service",
]
[[package]]
name = "indenter"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5"
[[package]]
name = "io-uring"
version = "0.7.9"
@@ -264,6 +307,12 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.175"
@@ -329,6 +378,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "owo-colors"
version = "4.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
[[package]]
name = "percent-encoding"
version = "2.3.1"
@@ -437,6 +492,15 @@ dependencies = [
"serde",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "slab"
version = "0.4.11"
@@ -476,6 +540,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
[[package]]
name = "thread_local"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
dependencies = [
"cfg-if",
]
[[package]]
name = "tokio"
version = "1.47.1"
@@ -550,6 +623,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
dependencies = [
"sharded-slab",
"thread_local",
"tracing-core",
]
[[package]]
@@ -558,11 +653,18 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "valuable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "wakey"
version = "0.0.0"
dependencies = [
"axum",
"color-eyre",
"tokio",
]
+1
View File
@@ -6,4 +6,5 @@ publish = ["gitea"]
[dependencies]
axum = "0.8.4"
color-eyre = "0.6.5"
tokio = "1.47.1"
+58 -41
View File
@@ -1,50 +1,67 @@
use std::{
collections::HashSet,
fs, iter,
net::IpAddr,
};
use std::{collections::HashSet, fs, iter, net::IpAddr};
use tokio::{io, net::UdpSocket};
#[tokio::main(flavor = "current_thread")]
async fn main() {
wake("lda.lan").await.unwrap();
}
async fn wake(machine_name: &str) -> io::Result<()> {
let sock = UdpSocket::bind("0.0.0.0:0").await?;
for (ip, mac) in find_mac(machine_name).await? {
let packet: Vec<u8> = iter::once([0xff; 6])
.chain(std::iter::repeat_n(mac, 16))
.flatten()
.collect();
sock.send_to(&packet, (ip, 9)).await?;
}
async fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
wake("lda.lan").await?;
Ok(())
}
async fn find_mac(machine_name: &str) -> io::Result<Vec<(IpAddr, [u8; 6])>> {
let arp = fs::read_to_string("/proc/net/arp")?;
let ips: HashSet<IpAddr> = tokio::net::lookup_host(machine_name)
.await?
.map(|c| c.ip())
.collect();
// async fn wake(machine_name: &str) -> io::Result<()> {
// let sock = UdpSocket::bind("0.0.0.0:0").await?;
// for (ip, mac) in find_mac(machine_name).await? {
// // println!("yo drop the {ip}/{mac:?}");
// let packet: Vec<u8> = iter::once([0xff; 6])
// .chain(std::iter::repeat_n(mac, 16))
// .flatten()
// .collect();
// // dbg!(&ip, &mac);
// sock.send_to(&packet, (ip, 9)).await?;
// }
// Ok(())
// }
Ok(arp
.lines()
.skip(1)
.filter_map(|line| {
let mut parts = line.split_ascii_whitespace();
let ip: IpAddr = parts.next()?.parse().ok()?;
if !ips.contains(&ip) {
return None;
}
let mac_str = parts.nth(2)?;
let mut mac = [0u8; 6];
for (byte, hex) in mac.iter_mut().zip(mac_str.split(':')) {
*byte = u8::from_str_radix(hex, 16).ok()?;
}
Some((ip, mac))
})
.collect())
// async fn find_mac(machine_name: &str) -> io::Result<Vec<(IpAddr, [u8; 6])>> {
// let arp = fs::read_to_string("/proc/net/arp")?;
// let ips: HashSet<IpAddr> = tokio::net::lookup_host((machine_name, 0))
// .await?
// .map(|c| c.ip())
// .collect();
// // dbg!(&ips, &arp);
// Ok(arp
// .lines()
// .skip(1)
// .filter_map(|line| {
// let mut parts = line.split_ascii_whitespace();
// let ip: IpAddr = parts.next()?.parse().ok()?;
// // println!("ip looks kinda good! {ip}");
// if !ips.contains(&ip) {
// return None;
// }
// let mac_str = parts.nth(2)?;
// let mut mac = [0u8; 6];
// for (byte, hex) in mac.iter_mut().zip(mac_str.split(':')) {
// *byte = u8::from_str_radix(hex, 16).ok()?;
// }
// Some((ip, mac))
// })
// .collect())
// }
async fn wake(_machine_name: &str) -> io::Result<()> {
let mac1 = [0x04, 0x7c, 0x16, 0x79, 0x6d, 0xee];
let mac2 = [0xbc, 0x09, 0x1b, 0xec, 0x65, 0xd0];
let suh = UdpSocket::bind("0.0.0.0:0").await?;
suh.set_broadcast(true)?;
for mac in [mac1, mac2] {
let pac: Vec<u8> = iter::once([0xff; 6])
.chain(iter::repeat_n(mac, 16))
.flatten()
.collect();
suh.send_to(&pac, "192.168.100.255:9").await?;
}
Ok(())
}