use flowscope::Asset;
use flowscope::arp;
use flowscope::asset::Inventory;
use flowscope::pcap::PcapFlowSource;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = std::env::args()
.nth(1)
.ok_or("usage: asset_inventory <trace.pcap>")?;
let mut inventory = Inventory::new(4096);
let mut arp_count = 0u64;
for view in PcapFlowSource::open(&path)?.views() {
let view = view?;
let Some(msg) = arp::parse_frame(&view.frame) else {
continue;
};
arp_count += 1;
inventory.absorb(Asset::from_arp(&msg));
}
println!(
"--- Inventory ({} assets, cap={}, from {arp_count} ARP messages) ---",
inventory.len(),
inventory.capacity(),
);
println!("{:<19} {:<16} {:<24} sources", "MAC", "IPv4", "hostname");
for (mac, asset) in inventory.iter() {
let ip = asset
.ipv4
.first()
.map(|i| i.to_string())
.unwrap_or_else(|| "-".to_string());
let hostname = asset.hostname.as_deref().unwrap_or("-");
println!("{mac} {ip:<16} {hostname:<24} {:?}", asset.seen_via);
}
Ok(())
}