async-port-scanner

Crates.ioasync-port-scanner
lib.rsasync-port-scanner
version0.1.4
sourcesrc
created_at2020-04-29 00:30:48.417698
updated_at2020-05-25 23:48:26.052107
descriptionSimple, yet fast, async port scanner library for Rust
homepagehttps://github.com/bparli/port-scanner
repositoryhttps://github.com/bparli/port-scanner
max_upload_size
id235173
size9,863
Ben Parli (bparli)

documentation

README

port-scanner

A simple, yet fast, async port scanner library for Rust. Built on async-std

Usage

A new Scanner only takes the timeout used for each port.

To run a port scan against localhost. This will return a vector of socket addresses that are listening on tcp:

  use async_std::task;
  use futures::future::join_all;
  use async_port_scanner::Scanner;
  let ps = Scanner::new(Duration::from_secs(4));

  let ftr = ps.run("127.0.0.1".to_string(), 1, 65535);
  let my_addrs: Vec<SocketAddr> = task::block_on(async { ftr.await });
  println!("{:?}", my_addrs);

It's easy to hit the open files limit on your system. To get around this, limit the scanner to running in batches of ports at a time:

  let ftr = ps.run_batched("127.0.0.1".to_string(), 1, 65535, 10000);
  let my_addrs: Vec<SocketAddr> = task::block_on(async { ftr.await });
  println!("{:?}", my_addrs);

You can also schedule scans against multiple hosts. This will return a vector of vectors of socket addresses.

  let my_ftr = ps.run_batched("127.0.0.1".to_string(), 1, 65535, 3000);
  let dev1_ftr = ps.run_batched("192.168.1.172".to_string(), 1, 65535, 3000);
  let dev2_ftr = ps.run_batched("192.168.1.137".to_string(), 1, 65535, 3000);
  let all_ftrs = vec![my_ftr, dev1_ftr, dev2_ftr];
  let results: Vec<Vec<SocketAddr>> = task::block_on(async move { join_all(all_ftrs).await });
  println!("{:?}", results);

Commit count: 21

cargo fmt