use ipnet::Ipv4Net;
use netscan::host::Host;
use netscan::scan::scanner::HostScanner;
use netscan::scan::setting::{HostScanSetting, HostScanType};
use std::net::{IpAddr, Ipv4Addr};
use std::time::Duration;
fn main() {
let interface = netdev::get_default_interface().unwrap();
let mut scan_setting: HostScanSetting = HostScanSetting::default()
.with_if_index(interface.index)
.with_scan_type(HostScanType::IcmpPingScan)
.with_timeout(Duration::from_millis(10000))
.with_wait_time(Duration::from_millis(500));
let src_ip: Ipv4Addr = interface.ipv4[0].addr();
let net: Ipv4Net = Ipv4Net::new(src_ip, 24).unwrap();
let nw_addr = Ipv4Net::new(net.network(), 24).unwrap();
for host in nw_addr.hosts() {
scan_setting.add_target(Host::new(IpAddr::V4(host), String::new()));
}
let result = HostScanner::new(scan_setting).scan();
println!("Status: {:?}", result.scan_status);
println!("UP Hosts:");
for host in result.hosts {
println!("{:?}", host);
}
println!("Scan Time: {:?} (including wait-time)", result.scan_time);
}