Feat: Erweitert get_ip_from_mac um Netzwerkparameter und verbessert Logging.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::process::Command;
|
||||
use std::net::Ipv4Addr;
|
||||
use crate::log;
|
||||
use crate::log::LogLevel;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::process::Command;
|
||||
|
||||
/// Prüft, ob eine angegebene IP-Adresse oder URL erreichbar ist
|
||||
///
|
||||
@@ -91,16 +91,19 @@ pub fn get_network_address(address: &str) -> Option<String> {
|
||||
///
|
||||
/// # Parameter
|
||||
/// - `mac`: MAC-Adresse im Format "xx:xx:xx:xx:xx:xx"
|
||||
/// - `network`: Netzwerkadresse im Format "xxx.xxx.xxx.xxx/yy"
|
||||
///
|
||||
/// # 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> {
|
||||
pub fn get_ip_from_mac(mac: &str, network: &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])
|
||||
.args(["-sn", "-n", "--system-dns", "-PR", network])
|
||||
.output();
|
||||
|
||||
log("network_utils", &*format!("{:?}", output), LogLevel::Debug);
|
||||
|
||||
match output {
|
||||
Ok(out) => {
|
||||
if !out.status.success() {
|
||||
@@ -108,13 +111,17 @@ pub fn get_ip_from_mac(mac: &str) -> Option<String> {
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
log("network_utils", &*stdout, LogLevel::Debug);
|
||||
|
||||
for line in stdout.lines() {
|
||||
if line.contains("Nmap scan report for") {
|
||||
if let Some(ip) = line.split_whitespace().last() {
|
||||
if line.contains(mac) {
|
||||
if let Some(ip_line) = line.split('\n').find(|l| l.contains("Nmap scan report for")) {
|
||||
if let Some(ip) = ip_line.split_whitespace().last() {
|
||||
return Some(ip.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user