Skip to content

Instantly share code, notes, and snippets.

@vitali2y
Created February 10, 2025 09:38
Show Gist options
  • Save vitali2y/734388204c15230496d3a232e6f0ac75 to your computer and use it in GitHub Desktop.
Save vitali2y/734388204c15230496d3a232e6f0ac75 to your computer and use it in GitHub Desktop.
Scan all IPs connected to home network
➜  nmap -sn 192.168.1.1-254/24 | egrep "scan report" | awk '{print $5}'
OpenWrt.lan
vernee_m6.lan
greenway.lan
192.168.1.147
➜
@vitali2y
Copy link
Author

ip -r n

@vitali2y
Copy link
Author

In Rust:

use std::{net::Ipv4Addr, time::Duration};
use tokio::task;

#[tokio::main]
async fn main() {
    let mut handles = vec![];

    for i in 1..=255 {
        handles.push(task::spawn(async move {
            let ip = Ipv4Addr::new(192, 168, 1, i);
            let result = ping::ping(
                std::net::IpAddr::V4(ip),
                Some(Duration::from_micros(10)),
                Some(1),
                None,
                None,
                None,
            );

            if result.is_ok() {
                println!("host is alive: {}", ip);
            }
        }));
    }

    for handle in handles {
        handle.await.unwrap();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment