Files
argus/src-tauri/src/models/host.rs
T
2026-09-23 09:16:09 -04:00

96 lines
2.1 KiB
Rust

use serde::{Deserialize, Serialize};
use std::net::IpAddr;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum HostStatus {
Up,
Down,
Filtered,
Unknown
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PingResult {
pub rtt_ms: f64,
pub ttl: Option<u8>,
pub loss_pct: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum Protocol {
Tcp,
Udp,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum PortState {
Open,
Closed,
Filtered,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PortResult {
pub port: u16,
pub protocol: Protocol,
pub state: PortState,
pub service: Option<String>,
pub banner: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NetbiosInfo {
pub computer_name: Option<String>,
pub workgroup: Option<String>,
pub mac_from_netbios: Option<String>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HostResult {
pub ip: IpAddr,
pub hostname: Option<String>,
pub mac: Option<String>,
pub vendor: Option<String>,
pub status: HostStatus,
pub ping: Option<PingResult>,
pub ports: Vec<PortResult>,
pub netbios: Option<NetbiosInfo>,
pub updated_at: u64,
}
fn now_ms() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64
}
impl HostResult {
pub fn from_ping(ip: IpAddr, ping: PingResult) -> Self {
Self {
ip,
hostname: None,
mac: None,
vendor: None,
status: HostStatus::Up,
ping: Some(ping),
ports: Vec::new(),
netbios: None,
updated_at: now_ms(),
}
}
pub fn down(ip: IpAddr) -> Self {
Self {
ip,
hostname: None,
mac: None,
vendor: None,
status: HostStatus::Down,
ping: None,
ports: Vec::new(),
netbios: None,
updated_at: now_ms(),
}
}
}