Feat: Fügt Funktion hinzu, die die IP-Adresse zu einer MAC-Adresse ermittelt.
This commit is contained in:
@@ -86,4 +86,49 @@ pub fn get_network_address(address: &str) -> Option<String> {
|
||||
|
||||
None
|
||||
}
|
||||
/// Ermittelt die IP-Adresse zu einer gegebenen MAC-Adresse im lokalen Netzwerk.
|
||||
/// Verwendet einen nmap-Scan, um das Gerät zu finden.
|
||||
///
|
||||
/// # Parameter
|
||||
/// - `mac`: MAC-Adresse im Format "xx:xx:xx:xx:xx:xx"
|
||||
///
|
||||
/// # Rückgabe
|
||||
/// - Option<String>: Die IP-Adresse des Geräts oder None wenn nicht gefunden
|
||||
pub fn get_ip_from_mac(mac: &str) -> Option<String> {
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
{
|
||||
let output = Command::new("nmap")
|
||||
.args(["-sn", "-n", "--system-dns", "-PR", "-PS22,80,443,445", "-PA80,443", "-PU161", mac])
|
||||
.output();
|
||||
|
||||
match output {
|
||||
Ok(out) => {
|
||||
if !out.status.success() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
for line in stdout.lines() {
|
||||
if line.contains("Nmap scan report for") {
|
||||
if let Some(ip) = line.split_whitespace().last() {
|
||||
return Some(ip.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
Err(e) => {
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
log::log("network_utils", "nmap is not installed on the system!", LogLevel::Error);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
|
||||
{
|
||||
log::log("network_utils", "OS not supported.", LogLevel::Error);
|
||||
None
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user