14 releases (8 breaking)

0.13.0 Nov 16, 2022
0.12.0 Jul 9, 2022
0.11.0 Jul 3, 2022
0.8.3 Feb 14, 2022
0.3.0 May 16, 2021

#935 in Network programming

Download history 18/week @ 2022-10-15 90/week @ 2022-10-22 81/week @ 2022-10-29 55/week @ 2022-11-05 85/week @ 2022-11-12 135/week @ 2022-11-19 70/week @ 2022-11-26 23/week @ 2022-12-03 52/week @ 2022-12-10 21/week @ 2022-12-17 17/week @ 2022-12-24 21/week @ 2022-12-31 30/week @ 2023-01-07 45/week @ 2023-01-14 33/week @ 2023-01-21 62/week @ 2023-01-28

171 downloads per month
Used in 3 crates (2 directly)

MIT license

140KB
3K SLoC

netscan Crates.io License

Cross-platform network scan library
with the aim of being lightweight and fast.

Features

  • Port Scan
    • TCP SYN scan
    • TCP CONNECT scan
  • Host Scan
    • ICMP PING scan
    • TCP PING scan

Usage

Add netscan to your dependencies

[dependencies]
netscan = "0.13.0"

Example

Port Scan Example

use netscan::blocking::PortScanner;
use netscan::setting::{ScanType, Destination};
use std::time::Duration;
use std::net::{IpAddr, Ipv4Addr};

fn main() {
    let mut port_scanner = match PortScanner::new(IpAddr::V4(Ipv4Addr::new(192, 168, 1, 4))) {
        Ok(scanner) => (scanner),
        Err(e) => panic!("Error creating scanner: {}", e),
    };
    // Add scan target
    let dst_ip: IpAddr = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 8));
    //let dst: Destination = Destination::new(dst_ip, vec![22, 80, 443]);
    let dst: Destination = Destination::new_with_port_range(dst_ip, 1, 1000);
    port_scanner.add_destination(dst);
    // Set options
    port_scanner.set_scan_type(ScanType::TcpSynScan);
    port_scanner.set_timeout(Duration::from_millis(10000));
    port_scanner.set_wait_time(Duration::from_millis(100));
    //port_scanner.set_send_rate(Duration::from_millis(1));
    // Run scan 
    let result = port_scanner.scan();
    // Print results 
    println!("Status: {:?}", result.scan_status);
    println!("Results:");
    for (ip, ports) in result.result_map {
        println!("{}", ip);
        for port in ports {
            println!("{:?}", port);
        }
    }
    println!("Scan Time: {:?}", result.scan_time);
}

Feature flags

The following feature flags can be used to enable/disable specific features.

--feature async

Enable async scanning.(Default feature)

--feature service

Enable service detection. (Experimental)

--feature os

Enable TCP/IP Stack Fingerprinting. (Experimental)

--feature full

Enable all of the above.

For more details see Examples

Supported platform

  • Linux
  • macOS
  • Windows

Note for Windows users

To build libpnet on Windows, follow the instructions below.

Windows

  • You must use a version of Rust which uses the MSVC toolchain
  • You must have WinPcap or npcap installed (tested with version WinPcap 4.1.3) (If using npcap, make sure to install with the "Install Npcap in WinPcap API-compatible Mode")
  • You must place Packet.lib from the WinPcap Developers pack in a directory named lib, in the root of this repository. Alternatively, you can use any of the locations listed in the %LIB%/$Env:LIB environment variables. For the 64 bit toolchain it is in WpdPack/Lib/x64/Packet.lib, for the 32 bit toolchain, it is in WpdPack/Lib/Packet.lib.

Source

Additional Notes

This library requires the ability to create raw sockets. Execute with administrator privileges.

Dependencies

~4–35MB
~600K SLoC