Scanner

Struct Scanner 

Source
pub struct Scanner {
Show 14 fields pub if_index: u32, pub if_name: String, pub src_mac: [u8; 6], pub dst_mac: [u8; 6], pub src_ip: IpAddr, pub src_port: u16, pub destinations: Vec<Destination>, pub scan_type: ScanType, pub timeout: Duration, pub wait_time: Duration, pub send_rate: Duration, pub scan_result: ScanResult, pub tx: Arc<Mutex<Sender<SocketAddr>>>, pub rx: Arc<Mutex<Receiver<SocketAddr>>>,
}
Available on crate feature sync only.
Expand description

Host Scanner

§Example

fn main() -> Result<(), String> {
#[cfg(feature = "sync")]
{
    use e_libscanner::sync_scan;
    use e_libscanner::Opts;
    use std::thread;
    // more command information use: -h
    let mut scanner = Opts::new(Some(&[
        "e-libscanner",
        "--ips",
        "192.168.1.0/24",
        "192.168.2-3.1-10",
        "baidu.com",
        "--model",
        "sync",
        "--scan",
        "Icmp",
        "--no-gui",
        "--",
        "-AS",
    ]))?
    .init()?
    .downcast::<sync_scan::Scanner>()
    .unwrap();
    let rx = scanner.get_progress_receiver();
    // Run scan
    let handle = thread::spawn(move || scanner.scan(None));
    // Print progress
    while let Ok(socket_addr) = rx.lock().unwrap().recv() {
        println!("Check: {}", socket_addr);
    }
    let result = handle.join().unwrap();
    // Print results
    println!("Status: {:?}", result.scan_status);
    println!("UP Hosts:");
    let len = result.ips.len();
    for host in result.ips {
        println!("{:?}", host);
    }
    println!("Scan Time: {:?} count[ {} ]", result.scan_time, len);
}
Ok(())
}

Fields§

§if_index: u32

Index of network interface

§if_name: String

Name of network interface

§src_mac: [u8; 6]

MAC address of network interface

§dst_mac: [u8; 6]

MAC address of default gateway(or scan target host)

§src_ip: IpAddr

Source IP address

§src_port: u16

Source port

§destinations: Vec<Destination>

Destinations

§scan_type: ScanType

Scan Type

§timeout: Duration

Timeout setting for entire scan task

§wait_time: Duration

Waiting time after packet sending task is completed

§send_rate: Duration

Packet sending interval(0 for unlimited)

§scan_result: ScanResult

Scan Result

§tx: Arc<Mutex<Sender<SocketAddr>>>

Sender for progress messaging

§rx: Arc<Mutex<Receiver<SocketAddr>>>

Receiver for progress messaging

Implementations§

Source§

impl Scanner

Source

pub fn new(src_ip: IpAddr) -> Result<Scanner, String>

Create new HostScanner with source IP address

Initialized with default value based on the specified IP address

Source

pub fn len(&self) -> usize

get scan count

Source

pub fn set_method(&mut self, cmd: &Vec<String>) -> Result<(), String>

Set method

Source

pub fn set_src_ip(&mut self, src_ip: IpAddr)

Set source IP address

Source

pub fn get_src_ip(&self) -> IpAddr

Get source IP address

Source

pub fn add_destination(&mut self, dst: Destination)

Add Destination

Source

pub fn set_destinations(&mut self, dst: Vec<Destination>)

Set Destinations

Source

pub fn get_destinations(&self) -> Vec<Destination>

Get Destinations

Source

pub fn set_scan_type(&mut self, scan_type: ScanType)

Set ScanType

Source

pub fn get_scan_type(&self) -> ScanType

Get ScanType

Source

pub fn set_timeout(&mut self, timeout: Duration)

Set timeout

Source

pub fn get_timeout(&self) -> Duration

Get timeout

Source

pub fn set_wait_time(&mut self, wait_time: Duration)

Set wait time

Source

pub fn get_wait_time(&self) -> Duration

Get wait time

Source

pub fn set_send_rate(&mut self, send_rate: Duration)

Set send rate

Source

pub fn get_send_rate(&self) -> Duration

Get send rate

Source

pub fn get_scan_result(&self) -> ScanResult

Get scan result

Source

pub fn get_progress_receiver(&self) -> Arc<Mutex<Receiver<SocketAddr>>>

Get progress receiver

Source

pub fn run_scan(&mut self, pstop: Option<Arc<Mutex<bool>>>)

Run Scan

Source

pub fn scan(&mut self, pstop: Option<Arc<Mutex<bool>>>) -> ScanResult

Run Sync scan and return result

Trait Implementations§

Source§

impl Clone for Scanner

Source§

fn clone(&self) -> Scanner

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Scanner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V