Skip to content

Commit

Permalink
more modes + utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrecknt committed Feb 6, 2024
1 parent dda83f4 commit 22f6417
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 61 deletions.
233 changes: 233 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'common'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=common"
],
"filter": {
"name": "common",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'database'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=database"
],
"filter": {
"name": "database",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'io'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=io"
],
"filter": {
"name": "io",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'mowojang'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=mowojang"
],
"filter": {
"name": "mowojang",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'mowojang'",
"cargo": {
"args": [
"build",
"--bin=mowojang",
"--package=mowojang"
],
"filter": {
"name": "mowojang",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'mowojang'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=mowojang",
"--package=mowojang"
],
"filter": {
"name": "mowojang",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'planning'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=planning"
],
"filter": {
"name": "planning",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'planning'",
"cargo": {
"args": [
"build",
"--bin=planning",
"--package=planning"
],
"filter": {
"name": "planning",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'planning'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=planning",
"--package=planning"
],
"filter": {
"name": "planning",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'web'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=web"
],
"filter": {
"name": "web",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'snowstorm'",
"cargo": {
"args": [
"build",
"--bin=snowstorm",
"--package=snowstorm"
],
"filter": {
"name": "snowstorm",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'snowstorm'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=snowstorm",
"--package=snowstorm"
],
"filter": {
"name": "snowstorm",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Scan the entire ipv4 address space for Minecraft servers, with dynamic scanning

> **Important**
> - The scanner is currently very early in development and is missing many features
> - The current version of the scanner is synchronous and single threaded, making it extremely slows
> - The scanner's adaptive scanning capabilities rely on already having some data to expand upon. If you do not already have a small number of servers in your database, the scanner will likely crash.
## Prerequisites

- Rust 1.77.0-nightly
- Rust 1.78.0-nightly
- Node.js 21.1.0 - for webui
- npm 10.2.4 - for webui
- A postgres database
Expand Down
21 changes: 21 additions & 0 deletions crates/common/src/network_range.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use serde::{Deserialize, Serialize};
use std::net::SocketAddrV4;

use crate::addr_range::Ipv4AddrRange;

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct SocketAddrV4Range {
pub start: SocketAddrV4,
Expand Down Expand Up @@ -93,3 +95,22 @@ impl PartialOrd for SocketAddrV4Range {
self.end.partial_cmp(&other.end)
}
}

impl From<(Ipv4AddrRange, u16, u16)> for SocketAddrV4Range {
fn from(value: (Ipv4AddrRange, u16, u16)) -> Self {
let (ip, port0, port1) = value;

SocketAddrV4Range::new(
SocketAddrV4::new(ip.first, port0),
SocketAddrV4::new(ip.last, port1),
)
}
}

impl From<(Ipv4AddrRange, u16)> for SocketAddrV4Range {
fn from(value: (Ipv4AddrRange, u16)) -> Self {
let (ip, port) = value;

(ip, port, port).into()
}
}
20 changes: 18 additions & 2 deletions crates/planning/src/asn.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use common::addr_range::Ipv4AddrRange;
use std::{collections::HashSet, net::Ipv4Addr};
use std::{
collections::{HashMap, HashSet},
net::Ipv4Addr,
};

pub fn get_slash24(ip: Ipv4Addr) -> Ipv4AddrRange {
let bits = u32::from(ip);
Ipv4AddrRange::new(
Ipv4Addr::from(bits & 0xffffff00),
Ipv4Addr::from(bits & 0xffffffff),
Ipv4Addr::from(bits | 0x000000ff),
)
}

Expand All @@ -19,3 +22,16 @@ pub fn get_slash24s(ips: &Vec<Ipv4Addr>) -> Vec<Ipv4AddrRange> {
}
ranges.iter().copied().collect()
}

pub fn get_slash24s_map_key(ips: &HashMap<Ipv4Addr, usize>) -> HashMap<Ipv4AddrRange, usize> {
let keys = ips.keys().map(|ip| get_slash24(*ip));
let mut res = HashMap::new();
for (k, v) in keys.zip(ips.values().copied()) {
if let Some(value) = res.get_mut(&k) {
*value += v;
} else {
res.insert(k, v);
}
}
res
}
2 changes: 2 additions & 0 deletions crates/planning/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const MIN_PORT: u16 = 1024;
pub const MAX_PORT: u16 = u16::MAX;
Loading

0 comments on commit 22f6417

Please sign in to comment.