Skip to content

Instantly share code, notes, and snippets.

@ironpillow
Forked from johshoff/main.rs
Created January 3, 2017 21:10
Show Gist options
  • Select an option

  • Save ironpillow/2124c30c336d7777133ddc6f61e8ce77 to your computer and use it in GitHub Desktop.

Select an option

Save ironpillow/2124c30c336d7777133ddc6f61e8ce77 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