cli
E. Almqvist 2 years ago
parent c075329920
commit dc723a58e1
  1. 1
      Cargo.toml
  2. 23
      src/ipv4.rs
  3. 4
      src/main.rs
  4. 9
      src/scanner.rs

@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
# packet = "0.1.4"
anyhow = "1" anyhow = "1"
log = "0.4" log = "0.4"
convert-base = "1.1.2" convert-base = "1.1.2"

@ -1,8 +1,8 @@
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use anyhow::{Result, anyhow};
use convert_base::Convert;
use crate::util; use crate::util;
use anyhow::{anyhow, Result};
use convert_base::Convert;
/* /*
Algorithm: O(n) Algorithm: O(n)
@ -17,7 +17,7 @@ let i = 0 .. u32:max_value()
pub struct IPv4 { pub struct IPv4 {
pub id: u64, pub id: u64,
pub ip: Vec<u8>, pub ip: Vec<u8>,
pub ignore: bool pub ignore: bool,
} }
impl IPv4 { impl IPv4 {
@ -37,7 +37,11 @@ impl IPv4 {
// Reverse it so that we start from the top // Reverse it so that we start from the top
ip = ip.into_iter().rev().collect(); ip = ip.into_iter().rev().collect();
Self { id, ip, ignore: false } Self {
id,
ip,
ignore: false,
}
} }
pub fn to_ipaddr(self: &mut Self) -> Result<IpAddr> { pub fn to_ipaddr(self: &mut Self) -> Result<IpAddr> {
@ -61,15 +65,20 @@ pub fn get_all(ignorelist: Option<Vec<u64>>) -> Result<Vec<IPv4>> {
// Get all of the "ids" // Get all of the "ids"
let ids: Vec<u32> = (0..u32::max_value()).collect(); let ids: Vec<u32> = (0..u32::max_value()).collect();
let ips: Vec<IPv4> = ids.iter().map(|&ip| { let ips: Vec<IPv4> = ids
.iter()
.map(|&ip| {
// Make IP // Make IP
let mut ip = IPv4::new(ip as u64); let mut ip = IPv4::new(ip as u64);
// Make the IP "ignored" if it is in the ignorelist // Make the IP "ignored" if it is in the ignorelist
if ignorelist.len() > 0 && ignorelist.contains(&ip.id) { ip.ignore = true; } if ignorelist.len() > 0 && ignorelist.contains(&ip.id) {
ip.ignore = true;
}
ip ip
}).collect(); })
.collect();
Ok(ips) Ok(ips)
} }

@ -4,9 +4,9 @@
//unused_imports, // TODO: rm //unused_imports, // TODO: rm
)] )]
mod util;
mod scanner;
mod ipv4; mod ipv4;
mod scanner;
mod util;
use ipv4::IPv4; use ipv4::IPv4;

@ -1,7 +1,10 @@
use std::{net::{TcpStream, SocketAddr}, thread::JoinHandle}; use crate::ipv4;
use log::info; use log::info;
use std::thread; use std::thread;
use crate::ipv4; use std::{
net::{SocketAddr, TcpStream},
thread::JoinHandle,
};
async fn check_ack(dest: &SocketAddr) -> bool { async fn check_ack(dest: &SocketAddr) -> bool {
if let Ok(res) = TcpStream::connect(dest) { if let Ok(res) = TcpStream::connect(dest) {
@ -25,7 +28,6 @@ pub fn start_scan(depth: u32) {
} }
} }
/* /*
depth: u32 depth: u32
@ -36,4 +38,3 @@ pre:
ALL_IPS: Vec<Vecu8>> = ... ALL_IPS: Vec<Vecu8>> = ...
*/ */

Loading…
Cancel
Save