Ich habe im Internet ein Code-Snippet gefunden mit den man die MAC Adresse über die IP heraus bekommt. Das Funktioniert auch wunderbar, aber geht das auch in "schöner" oder ein Process zu nutzen?
So schaut die Methode aus:
private string GetMacAddress(string ipAddress)
{
string macAddress = string.Empty;
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = "arp";
pProcess.StartInfo.Arguments = "-a " + ipAddress;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true;
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();
string[] substrings = strOutput.Split('-');
if (substrings.Length >= 8)
{
macAddress = substrings[3].Substring(Math.Max(0, substrings[3].Length - 2))
+ "-" + substrings[4] + "-" + substrings[5] + "-" + substrings[6]
+ "-" + substrings[7] + "-"
+ substrings[8].Substring(0, 2);
return macAddress;
}
else
{
return "not found";
}
Deine eigentliche Frage ist: wie nutzt man ARP in Managed Code.
Einmal Google nutzen nach .NET ARP: https://github.com/abock/arp
Ich bin mir sicher, dass Deine Recherche auch Treffer für Windows ausspucken wird. 😃
Ansonsten kannst Du aus .NET einfach die Win32 Schnittstelle ansprechen:
SendARP function
Bitte in Zukunft wenigstens zwei Minuten die Suchmaschine Deiner Wahl verwenden 😉
- performance is a feature -
Microsoft MVP - @Website - @AzureStuttgart - github.com/BenjaminAbt - Sustainable Code
Vielen Dank für die Links!
Ich hatte dazu bereits im Netz gesucht, aber nur Beispiele gefunden wie man über ein Process auf die arp zugreift.