在C#中相同LAN上的IP地址到MAC地址的IP地址

问题描述:

有没有办法在C#中找到MAC地址与IP地址之间的映射。我认为RARP应该能够做到这一点,是否有一个在C#中可用的API在C#中相同LAN上的IP地址到MAC地址的IP地址

+0

重复问题:http://*.com/questions/1148778/how-do-i-access-arp-protocol-information- through-c-net – mjv 2010-02-05 00:53:32

为什么不产生一个进程调用rarp并从进程的输出读入输入流?这是做一个真正的廉价和简单的方式开朗......*的我的头,它是这样的:

 
System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo("arp", "-a"); 
ps.CreateNoWindow = false; 
ps.RedirectStandardOutput = true; 
using (System.Diagnostics.Process proc = new System.Diagnostics.Process()) 
{ 
    proc.StartInfo = ps; 
    proc.Start(); 
    System.IO.StreamReader sr = proc.StandardOutput; 
    while (!proc.HasExited) ; 
    string sResults = sr.ReadToEnd(); 
} 

然后,它的解析sResults获得MAC地址的问题。

如果你正在寻找一个基于API的方法并不能做的Process.Start()来看看这个:

http://www.codeproject.com/KB/IP/host_info_within_network.aspx

它允许主机名,IP地址的映射和MAC地址。