cli
E. Almqvist 2 years ago
parent c075329920
commit dc723a58e1
  1. 1
      Cargo.toml
  2. 35
      src/ipv4.rs
  3. 4
      src/main.rs
  4. 11
      src/scanner.rs
  5. 6
      src/util.rs

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

@ -1,8 +1,8 @@
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use anyhow::{Result, anyhow};
use convert_base::Convert;
use crate::util;
use anyhow::{anyhow, Result};
use convert_base::Convert;
/*
Algorithm: O(n)
@ -17,7 +17,7 @@ let i = 0 .. u32:max_value()
pub struct IPv4 {
pub id: u64,
pub ip: Vec<u8>,
pub ignore: bool
pub ignore: bool,
}
impl IPv4 {
@ -29,7 +29,7 @@ impl IPv4 {
// In case we are missing some digits
if ip.len() < 4 {
for i in 0..(4-ip.len()) {
for i in 0..(4 - ip.len()) {
ip.insert(0, 0);
}
}
@ -37,11 +37,15 @@ impl IPv4 {
// Reverse it so that we start from the top
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> {
if let [a, b, c, d] = self.ip[0..3] {
if let [a, b, c, d] = self.ip[0..3] {
Ok(IpAddr::V4(Ipv4Addr::new(a, b, c, d)))
} else {
Err(anyhow!("Unable to unpack IPv4 address"))
@ -61,15 +65,20 @@ pub fn get_all(ignorelist: Option<Vec<u64>>) -> Result<Vec<IPv4>> {
// Get all of the "ids"
let ids: Vec<u32> = (0..u32::max_value()).collect();
let ips: Vec<IPv4> = ids.iter().map(|&ip| {
// Make IP
let mut ip = IPv4::new(ip as u64);
let ips: Vec<IPv4> = ids
.iter()
.map(|&ip| {
// Make IP
let mut ip = IPv4::new(ip as u64);
// Make the IP "ignored" if it is in the ignorelist
if ignorelist.len() > 0 && ignorelist.contains(&ip.id) { ip.ignore = true; }
// Make the IP "ignored" if it is in the ignorelist
if ignorelist.len() > 0 && ignorelist.contains(&ip.id) {
ip.ignore = true;
}
ip
}).collect();
ip
})
.collect();
Ok(ips)
}

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

@ -1,7 +1,10 @@
use std::{net::{TcpStream, SocketAddr}, thread::JoinHandle};
use crate::ipv4;
use log::info;
use std::thread;
use crate::ipv4;
use std::{
net::{SocketAddr, TcpStream},
thread::JoinHandle,
};
async fn check_ack(dest: &SocketAddr) -> bool {
if let Ok(res) = TcpStream::connect(dest) {
@ -18,14 +21,13 @@ pub fn start_scan(depth: u32) {
for i in 0..depth {
let thread = thread::spawn(|| {
println!("hi");
println!("hi");
// do scan
});
threads.push(thread);
}
}
/*
depth: u32
@ -36,4 +38,3 @@ pre:
ALL_IPS: Vec<Vecu8>> = ...
*/

@ -10,8 +10,8 @@ uint ulong_len(ulong n) { // get the nth_digit length of a number
*/
fn nth_digit(num: u64, idx: u32) -> u8 {
// ((num % (10**(idx+1))) - (num % (10**idx)))/(10**idx)
(((num % (10_u64.pow(idx+1))) - (num % (10_u64.pow(idx))))/(10_u64.pow(idx))) as u8
// ((num % (10**(idx+1))) - (num % (10**idx)))/(10**idx)
(((num % (10_u64.pow(idx + 1))) - (num % (10_u64.pow(idx)))) / (10_u64.pow(idx))) as u8
}
fn numlen(mut num: u64) -> u8 {
@ -35,7 +35,7 @@ pub fn number_to_vec(num: u64) -> Vec<u8> {
for idx in 0..len {
let digit = nth_digit(num, idx as u32);
out.push(digit);
out.push(digit);
}
out

Loading…
Cancel
Save