mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Added MAC vendor lookup
This commit is contained in:
Generated
+28
@@ -139,6 +139,12 @@ version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.18"
|
||||
@@ -220,6 +226,8 @@ dependencies = [
|
||||
"env_logger",
|
||||
"log",
|
||||
"pnet",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -427,6 +435,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -449,6 +458,19 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.149"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.8"
|
||||
@@ -642,3 +664,9 @@ name = "windows_x86_64_msvc"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94f63c051f4fe3c1509da62131a678643c5b6fbdc9273b2b79d4378ebda003d2"
|
||||
|
||||
@@ -8,3 +8,5 @@ env_logger = "0.11.8"
|
||||
log = "0.4.29"
|
||||
pnet = "0.35.0"
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,6 +7,12 @@ pub struct Device {
|
||||
pub ipv4_address: String,
|
||||
}
|
||||
|
||||
impl Device {
|
||||
pub fn get_mac_prefix(&self) -> String {
|
||||
self.mac_address.get(0..8).unwrap_or("").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Device {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "mac={}, ip={}", self.mac_address, self.ipv4_address)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
use log::{debug, info, warn};
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
pub struct MacVendorFinder {
|
||||
mac_vendors_database: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct MacRecord {
|
||||
pub mac_prefix: String,
|
||||
pub vendor_name: String,
|
||||
// private: bool,
|
||||
// block_type: String,
|
||||
// last_update: String,
|
||||
}
|
||||
|
||||
impl MacVendorFinder {
|
||||
pub fn new() -> MacVendorFinder {
|
||||
info!("Loading MAC vendor database into memory");
|
||||
|
||||
let mut database = HashMap::new();
|
||||
let data = fs::read_to_string("data/mac-vendors-export.json").unwrap();
|
||||
let json: Vec<MacRecord> = serde_json::from_str(&data).unwrap();
|
||||
|
||||
debug!("Found {} records in the database", json.len());
|
||||
|
||||
for el in json {
|
||||
database.insert(el.mac_prefix.to_uppercase(), el.vendor_name);
|
||||
}
|
||||
|
||||
info!("MAC vendor database loaded");
|
||||
|
||||
MacVendorFinder {
|
||||
mac_vendors_database: database,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find(&mut self, mac_prefix: &str) -> Option<&String> {
|
||||
self.mac_vendors_database
|
||||
.get(mac_prefix.to_uppercase().as_str())
|
||||
}
|
||||
}
|
||||
+12
-1
@@ -1,18 +1,29 @@
|
||||
use log::info;
|
||||
|
||||
use crate::mac_vendor_finder::MacVendorFinder;
|
||||
mod config;
|
||||
mod device_finders;
|
||||
mod mac_vendor_finder;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
env_logger::init();
|
||||
info!("Starting up oott");
|
||||
|
||||
let devices = device_finders::arp::find("wlp1s0").await;
|
||||
let mut mac_vendor_finder = MacVendorFinder::new();
|
||||
|
||||
let devices = device_finders::arp::find("eno1").await;
|
||||
|
||||
info!("Done with ARP probes");
|
||||
info!("Found {} online devices", devices.iter().count());
|
||||
for device in devices.iter() {
|
||||
info!("Device found {}", device);
|
||||
let vendor_result = mac_vendor_finder.find(device.get_mac_prefix().as_str());
|
||||
match vendor_result {
|
||||
Some(vendor) => info!("Device vendor = {}", vendor),
|
||||
None => info!("Device vendor not found"),
|
||||
}
|
||||
}
|
||||
|
||||
info!("Exiting");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user