Skip to content

Instantly share code, notes, and snippets.

@johshoff
Created November 15, 2016 04:31
Show Gist options
  • Save johshoff/bed463ce8a122123e60bbc84bd1b1129 to your computer and use it in GitHub Desktop.
Save johshoff/bed463ce8a122123e60bbc84bd1b1129 to your computer and use it in GitHub Desktop.
scan ips
use std::thread;
use std::net::TcpStream;
fn check_open_port(host: &str, port: u16) -> bool {
TcpStream::connect((host, port)).is_ok()
}
fn main() {
const PORT : u16 = 22;
println!("Scanning for port {}", PORT);
let mut threads = Vec::new();
for x in 1..254 {
let ip = format!("192.168.1.{:?}", x);
threads.push(thread::spawn(move || {
if check_open_port(&ip, PORT) {
println!("{}:{}", ip, PORT);
}
}));
}
for thread in threads {
thread.join().unwrap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment