is the most patchy thing

This commit is contained in:
ldlda
2025-08-22 02:09:03 +07:00 Unverified
parent 402a9d401e
commit 4e9867f844
2 changed files with 27 additions and 13 deletions
+10 -10
View File
@@ -1,25 +1,26 @@
use std::iter;
use tokio::{
io,
net::{TcpListener, UdpSocket},
};
use axum::{Router, response::Html, routing::get};
use tokio::net::TcpListener;
mod utils;
use utils::*;
async fn home() -> Html<&'static str> {
Html(
async fn home() -> Html<String> {
Html(format!(
r#"
<html>
<body>
<p>the machine is {}!</p>
<form method="POST" action="/wake">
<button type="submit">Wake LDA</button>
</form>
</body>
</html>
"#,
)
if ping_ip("192.168.100.94:22").await {
"on"
} else {
"off"
}
))
}
async fn wake_handler() -> &'static str {
@@ -40,4 +41,3 @@ async fn main() -> color_eyre::Result<()> {
axum::serve(port, app.into_make_service()).await?;
Ok(())
}
+17 -3
View File
@@ -1,9 +1,13 @@
pub const LDA_MACS: [[u8; 6]; 2] = [
[0x04, 0x7c, 0x16, 0x79, 0x6d, 0xee],
[0xbc, 0x09, 0x1b, 0xec, 0x65, 0xd0],
];
pub 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] {
for mac in LDA_MACS {
let pac: Vec<u8> = iter::once([0xff; 6])
.chain(iter::repeat_n(mac, 16))
.flatten()
@@ -29,3 +33,13 @@ pub async fn ping_ip<T: ToSocketAddrs>(addr: T) -> bool {
}
// pub async fn get_ips(macs: &[&[u8;6]]) -> Vec<IpAddr> {
// /*
// root@AP-AX3000CV2-0A55:~# ip neigh show 192.168.100.94
// 192.168.100.94 dev eth1.6 FAILED
// 192.168.100.94 dev br-lan lladdr 04:7c:16:79:6d:ee REACHABLE
// 192.168.100.94 dev eth1.7 FAILED
// 192.168.100.94 dev eth1.5 FAILED
// */
// }