mirror of
https://git.funtimes909.xyz/ServerSeekerV2/ServerSeekerV2.git
synced 2026-10-12 02:18:11 +08:00
masscan stuff
This commit is contained in:
1 parent
e9dba45ab1
commit
8d09204c81
1 file changed
+50
@@ -0,0 +1,50 @@
|
||||
use serde::Deserialize;
|
||||
use std::io::Read;
|
||||
use std::process::Command;
|
||||
|
||||
// TODO: Better name for this struct
|
||||
#[derive(Deserialize)]
|
||||
pub struct MasscanServer {
|
||||
pub ip: String,
|
||||
pub ports: Vec<Port>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Port {
|
||||
port: u16,
|
||||
}
|
||||
|
||||
pub fn start_masscan(masscan_config: String) {
|
||||
let mut output = if cfg!(target_os = "windows") {
|
||||
Command::new("cmd.exe")
|
||||
.arg("/c")
|
||||
.arg(format!("masscan -c {masscan_config}"))
|
||||
.spawn()
|
||||
.expect("failed to execute process")
|
||||
} else {
|
||||
Command::new("/bin/sh")
|
||||
.arg("-c")
|
||||
// Masscan needs to be run as root, nothing I can do about it
|
||||
// TODO! Change this to be a toggle in the config for security
|
||||
.arg(format!("sudo masscan -c {masscan_config}"))
|
||||
.spawn()
|
||||
.expect("failed to execute process")
|
||||
};
|
||||
|
||||
output.wait().expect("failed to wait on child");
|
||||
}
|
||||
|
||||
pub fn parse_output(masscan_output: String) -> Vec<(String, u16)> {
|
||||
let file = std::fs::read_to_string(masscan_output).expect("failed to read masscan");
|
||||
let output = serde_json::from_str::<Vec<MasscanServer>>(&file).expect("failed to read masscan");
|
||||
let mut servers = vec![];
|
||||
|
||||
// TODO: I know this can be done better
|
||||
for server in output {
|
||||
for port in server.ports {
|
||||
servers.push((server.ip.clone(), port.port));
|
||||
}
|
||||
}
|
||||
|
||||
servers
|
||||
}
|
||||
Reference in new issue
Block a user