编程如何实现通过MAC地址获其对应的IP地址?

解决方案 »

  1.   

    通过MAC获得对应的IP好象必须通过交换机进行处理了
      

  2.   

    例如,使用SNMP,也就是简单网管协议
      

  3.   

    用ARP,从网络服务器中的到MAC。[DllImport("iphlpapi.dll", ExactSpelling=true)]
    public static extern int SendARP( int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen ); // Use Your work Group WinNT://&&&&(Work Group Name)
    DirectoryEntry DomainEntry = new DirectoryEntry("WinNT://" + "workgroup");
    DomainEntry.Children.SchemaFilter.Add("computer");
    // To Get all the System names And Display with the Ip Address
    foreach(DirectoryEntry machine in DomainEntry.Children)
    {
    string[] Ipaddr = new string[3];
    Ipaddr[0] = machine.Name; System.Net.IPHostEntry Tempaddr = null; try
    {
    Tempaddr = (System.Net.IPHostEntry)Dns.GetHostByName(machine.Name);
    }
    catch(Exception ex)
    {
    MessageBox.Show("Unable to connect woth the system :" + machine.Name );
    continue;
    }
    System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
    foreach(IPAddress TempA in TempAd)
    {
    Ipaddr[1] = TempA.ToString(); byte[] ab = new byte[6];
    int len = ab.Length; // This Function Used to Get The Physical Address
    int r = SendARP( (int) TempA.Address, 0, ab, ref len );
    string mac = BitConverter.ToString( ab, 0, 6 ); Ipaddr[2] = mac;
    }
    System.Windows.Forms.ListViewItem TempItem = new ListViewItem(Ipaddr); this.ListHostIP.Items.Add(TempItem);
    }
      

  4.   

    哦,看错了,你可以根据IP得到MAC添加到NameValueCollocation中,然后根据MAC的到IP^_^