e_libscanner/lib.rs
1//! A fast network scan tools of library
2//! # Quick start
3//! ```
4//! fn main() -> Result<(), String> {
5//! #[cfg(feature = "sync")]
6//! {
7//! use e_libscanner::sync_scan;
8//! use e_libscanner::Opts;
9//! use std::thread;
10//! // more command information use: -h
11//! let mut scanner = Opts::new(Some(&[
12//! "e-libscanner",
13//! "--ips",
14//! "192.168.1.0/24",
15//! "192.168.2-3.1-10",
16//! "baidu.com",
17//! "--model",
18//! "sync",
19//! "--scan",
20//! "Icmp",
21//! "--no-gui",
22//! "--",
23//! "-AS",
24//! ]))?
25//! .init()?
26//! .downcast::<sync_scan::Scanner>()
27//! .unwrap();
28//! let rx = scanner.get_progress_receiver();
29//! // Run scan
30//! let handle = thread::spawn(move || scanner.scan(None));
31//! // Print progress
32//! while let Ok(socket_addr) = rx.lock().unwrap().recv() {
33//! println!("Check: {}", socket_addr);
34//! }
35//! let result = handle.join().unwrap();
36//! // Print results
37//! println!("Status: {:?}", result.scan_status);
38//! println!("UP Hosts:");
39//! let len = result.ips.len();
40//! for host in result.ips {
41//! println!("{:?}", host);
42//! }
43//! println!("Scan Time: {:?} count[ {} ]", result.scan_time, len);
44//! }
45//! Ok(())
46//! }
47//! ```
48
49#![doc(
50 html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
51 html_favicon_url = "https://www.rust-lang.org/favicon.ico",
52 html_root_url = "https://github.com/EternalNight996",
53)]
54#![warn(
55 missing_debug_implementations,
56 rustdoc::missing_doc_code_examples,
57 missing_docs,
58 rust_2018_idioms,
59 unreachable_pub,
60 bad_style,
61 const_err,
62 dead_code,
63 improper_ctypes,
64 non_shorthand_field_patterns,
65 no_mangle_generic_items,
66 overflowing_literals,
67 path_statements,
68 patterns_in_fns_without_body,
69 private_in_public,
70 unconditional_recursion,
71 unused,
72 unused_allocation,
73 unused_comparisons,
74 unused_parens,
75 while_true
76)]
77#![doc(test(attr(allow(unused_variables), deny(warnings))))]
78#![cfg_attr(doc_cfg, feature(doc_cfg))]
79// Rustc lints.
80#![deny(missing_docs, unused_imports)]
81
82
83/// Async Host Scanner
84/// # Example
85/// ```
86/// fn main() -> Result<(), String> {
87/// #[cfg(feature = "async")]
88/// {
89/// use e_libscanner::{async_scan, Opts};
90/// use std::thread;
91/// // more command information use: -h
92/// let mut scanner = Opts::new(Some(&[
93/// "e-libscanner",
94/// "--ips",
95/// "192.168.20.0/23",
96/// "192.168.28-31.1-10",
97/// "baidu.com",
98/// "--model",
99/// "async",
100/// "--scan",
101/// "icmp",
102/// "--no-gui",
103/// ]))?
104/// .init()?
105/// .downcast::<async_scan::Scanner>()
106/// .unwrap();
107/// let rx = scanner.get_progress_receiver();
108/// // Run scan
109/// let handle = thread::spawn(move || async_io::block_on(async { scanner.scan(None).await }));
110/// // Print progress
111/// while let Ok(socket_addr) = rx.lock().unwrap().recv() {
112/// println!("Check: {}", socket_addr);
113/// }
114/// let result = handle.join().unwrap();
115/// // Print results
116/// println!("Status: {:?}", result.scan_status);
117/// println!("UP Hosts:");
118/// let len = result.ips.len();
119/// for host in result.ips {
120/// println!("{:?}", host);
121/// }
122/// println!("Scan Time: {:?} count[ {} ]", result.scan_time, len);
123/// }
124/// Ok(())
125/// }
126/// ```
127#[cfg(feature = "async")]
128#[cfg_attr(doc_cfg, doc(cfg(feature = "async")))]
129pub mod async_scan;
130
131/// Host Scanner
132/// # Examples
133/// ```
134/// {
135/// use e_libscanner::sync_scan;
136/// use e_libscanner::Opts;
137/// use std::thread;
138/// // more command information use: -h
139/// let mut scanner = Opts::new(Some(&[
140/// "e-libscanner",
141/// "--ips",
142/// "192.168.1.0/24",
143/// "192.168.2-3.1-10",
144/// "baidu.com",
145/// "--model",
146/// "sync",
147/// "--scan",
148/// "Icmp",
149/// "--no-gui",
150/// "--",
151/// "-AS",
152/// ]))?
153/// .init()?
154/// .downcast::<sync_scan::Scanner>()
155/// .unwrap();
156/// let rx = scanner.get_progress_receiver();
157/// // Run scan
158/// let handle = thread::spawn(move || scanner.scan(None));
159/// // Print progress
160/// while let Ok(socket_addr) = rx.lock().unwrap().recv() {
161/// println!("Check: {}", socket_addr);
162/// }
163/// let result = handle.join().unwrap();
164/// // Print results
165/// println!("Status: {:?}", result.scan_status);
166/// println!("UP Hosts:");
167/// let len = result.ips.len();
168/// for host in result.ips {
169/// println!("{:?}", host);
170/// }
171/// println!("Scan Time: {:?} count[ {} ]", result.scan_time, len);
172/// }
173/// Ok(())
174/// }
175/// ```
176#[cfg(feature = "sync")]
177#[cfg_attr(doc_cfg, doc(cfg(feature = "sync")))]
178pub mod sync_scan;
179
180/// Struct for service detection
181/// # Example
182/// ```
183/// fn main() -> Result<(), String> {
184/// #[cfg(feature = "service")]
185/// {
186/// use e_libscanner::service::{self, PortDatabase, ServiceDetector};
187/// use e_libscanner::Opts;
188/// use std::thread;
189/// // more command information use: -h
190/// let mut scanner = Opts::new(Some(&[
191/// "e-libscanner",
192/// "--ips",
193/// "192.168.80.10",
194/// "--ports",
195/// "8000",
196/// "8080",
197/// "20-100",
198/// "--rate",
199/// "1",
200/// "--model",
201/// "service",
202/// "--scan",
203/// "tcpsyn",
204/// "--no-gui",
205/// ]))?
206/// .init()?
207/// .downcast::<service::Scanner>()
208/// .unwrap();
209/// let rx = scanner.get_progress_receiver();
210/// let time = std::time::Instant::now();
211/// // Run scan
212/// let handle = thread::spawn(move || scanner.scan(None));
213/// // Print progress
214/// while let Ok(socket_addr) = rx.lock().unwrap().recv() {
215/// println!("Check: {}", socket_addr);
216/// }
217/// let result = handle.join().unwrap();
218/// for (ip, _ports) in result.ip_with_port.clone() {
219/// let mut service_detector = ServiceDetector::new();
220/// service_detector.set_dst_ip(ip);
221/// service_detector.set_open_ports(result.get_open_ports(ip));
222/// println!("{}", service_detector.scan(Some(PortDatabase::default())));
223/// }
224/// println!("time -> {}/s", time.elapsed().as_secs_f64());
225/// }
226/// Ok(())
227/// }
228/// ```
229#[cfg(feature = "service")]
230#[cfg_attr(doc_cfg, doc(cfg(feature = "service")))]
231pub mod service;
232
233/// Struct for fingerprint probe
234/// # Example
235/// ```
236/// fn main() -> Result<(), String> {
237/// #[cfg(feature = "os")]
238/// {
239/// use e_libscanner::os;
240/// use e_libscanner::Opts;
241/// // more command information use: -h
242/// let mut scanner = Opts::new(Some(&[
243/// "e-libscanner",
244/// "--ips",
245/// "192.168.80.8",
246/// "192.168.80.1",
247/// "--ports",
248/// "80",
249/// "135",
250/// "554",
251/// "8000",
252/// "22",
253/// "--model",
254/// "os",
255/// "--no-gui",
256/// "--",
257/// "-AS",
258/// ]))?
259/// .init()?
260/// .downcast::<os::Scanner>()
261/// .unwrap();
262/// let results = scanner.scan(None);
263/// for result in results {
264/// println!("{}", result.ip_addr);
265/// println!("{:?}", result.icmp_echo_result);
266/// println!("{:?}", result.icmp_timestamp_result);
267/// println!("{:?}", result.icmp_address_mask_result);
268/// println!("{:?}", result.icmp_information_result);
269/// println!("{:?}", result.icmp_unreachable_ip_result);
270/// println!("{:?}", result.icmp_unreachable_data_result);
271/// println!("{:?}", result.tcp_syn_ack_result);
272/// println!("{:?}", result.tcp_rst_ack_result);
273/// println!("{:?}", result.tcp_ecn_result);
274/// println!("{:?}", result.tcp_header_result);
275/// println!();
276/// }
277/// Ok(())
278/// }
279/// }
280/// ```
281#[cfg(feature = "os")]
282#[cfg_attr(doc_cfg, doc(cfg(feature = "os")))]
283pub mod os;
284
285/// Static data model
286pub mod data;
287/// Struct model
288pub mod frame;
289/// Network interface api
290pub mod interface;
291/// Network packet model
292pub mod packet;
293/// Network utils
294mod utils;
295/// Network utils
296pub use utils::*;