我现在能循环获取局域网同一网段内的所有在线主机能对某个指定的IP获取其MAC地址现在如何获取局域网内所有在线主机IP对应的MAC地址???谢谢!!!

解决方案 »

  1.   

    DirectoryEntry root = new DirectoryEntry("WinNT:");  
      DirectoryEntries domains = root.Children;  
      domains.SchemaFilter.Add("domain");  
      foreach (DirectoryEntry domain in domains) {  
      IPHostEntry iphe = null;  
      try {  
      iphe = Dns.GetHostByName(computer.Name);  
      }  
      catch { }  
      }
    //获取MAC
    SendARP
    public string getRemoteMac(string localIP, string remoteIP) 

       Int32 ldest= inet_addr(remoteIP); //目的ip 
       Int32 lhost= inet_addr(localIP); //本地ip    try 
       { 
        Int64 macinfo = new Int64(); 
        Int32 len = 6; 
        int res = SendARP(ldest,0, ref macinfo, ref len); 
        return Convert.ToString(macinfo,16); 
       } 
       catch(Exception err) 
       { 
        Console.WriteLine("Error:{0}",err.Message); 
       } 
       return 0.ToString();

      

  2.   

    这个可以实现获取所有mac地址吗?