I am trying to write a discovery function in Rust that discovers the device IP in LAN, this function should sends HTTP requests for all possible IPs in the IP space and once receives 200 status return the value and cancels all others requests (by dropping the future in case reqwest used)
async fn discover() -> Result<String, ()> {
for i in 0..256 {
tokio::spawn(async move {
let url = format!("http://192.168.0.{i}:8000/ping");
reqwest::get(url).await;
});
}
}
Edit 1
once receives 200 status return the value and cancels all others requests
We would like to also validate the response content to make sure that this is the correct device and not someone who is trying to spy on the network we will validate the response by verifying the JWT token returning from the /ping
endpoint, how can we do this