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, 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, pub banner: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct NetbiosInfo { pub computer_name: Option, pub workgroup: Option, pub mac_from_netbios: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct HostResult { pub ip: IpAddr, pub hostname: Option, pub mac: Option, pub vendor: Option, pub status: HostStatus, pub ping: Option, pub ports: Vec, pub netbios: Option, 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(), } } }