Skip to content

Conversation

PsypherPunk
Copy link
Collaborator

  • add lib.rs (permitted as per Packages and Crates).
  • refactor main.rs to reference the library.
  • update module references as required.

relates #497

By way of example, configuring a new binary project which references this crate:

[dependencies]
async-std = "^1.7"
rustscan = { path = "/home/rust/git/RustScan" }

…allows rustscan to be referenced as a library:

use async_std::task::block_on;
use std::{net::IpAddr, time::Duration};

use rustscan::input::{PortRange, ScanOrder};
use rustscan::port_strategy::PortStrategy;
use rustscan::scanner::Scanner;

fn main() {
    let addrs = vec!["127.0.0.1".parse::<IpAddr>().unwrap()];
    let range = PortRange {
        start: 1,
        end: 1_000,
    };
    let strategy = PortStrategy::pick(&Some(range), None, ScanOrder::Random);
    let scanner = Scanner::new(
        &addrs,
        10,
        Duration::from_millis(100),
        1,
        true,
        strategy,
        true,
        vec![9000],
    );

    let scan_result = block_on(scanner.run());

    println!("{:?}", scan_result);
}

@PsypherPunk
Copy link
Collaborator Author

Also, tests pass except that as this is now a library, doc-tests are running and failing.

@bee-san
Copy link
Owner

bee-san commented Apr 11, 2024

Wow this is cool!!!! A long awaited feature. I think some docs on how to use the library would be great too 🥳

- add `lib.rs` (permitted as per
  [_Packages and Crates_](https://doc.rust-lang.org/book/ch07-01-packages-and-crates.html)).
- refactor `main.rs` to reference the library.
- update module references as required.
@PsypherPunk PsypherPunk force-pushed the 497-rustscan-as-a-library branch from b657479 to 994aff1 Compare April 12, 2024 09:10
- fix some failing doc-tests.
- amend formatting causing misinterpretation as code-samples.
- mark some examples as
  [`compile_fail`](https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#attributes)
  as there's no immediate way to instantiate the required `struct`.
@PsypherPunk PsypherPunk force-pushed the 497-rustscan-as-a-library branch from 994aff1 to a5b50d9 Compare April 12, 2024 09:22
@PsypherPunk
Copy link
Collaborator Author

@bee-san, I've fixed the failing parts:

  • fixed the doc-tests in src/benchmark/mod.rs.
  • changed the indentation in src/scripts/mod.rs as this was being interpreted as code—this might need a review as I'm not sure if it looks as intended in the resulting doc. output.
  • I've marked a couple in src/scanner/mod.rs as compile_fail; I don't think there's a particularly easy way to instantiate a Scanner for the examples—I suppose things like this are going to be raised if this is to be used as a library; should there be a sensible Default for Scanner?

Re. the "docs on how to use the library", I'll see what I can do…

- add lib-level docs. including a minimal example.
- add minimal, headline information for each module.
@PsypherPunk PsypherPunk marked this pull request as ready for review April 12, 2024 14:04
@bee-san bee-san merged commit b9337d8 into bee-san:master Apr 14, 2024
@bee-san
Copy link
Owner

bee-san commented Apr 14, 2024

Wow! Thank you so much!!

@PsypherPunk PsypherPunk deleted the 497-rustscan-as-a-library branch April 14, 2024 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants