如题,谢谢!!

解决方案 »

  1.   

    public static string GetRemoteMAC(string localIP, string remoteIP)
    {
    Int32 ldest= inet_addr(remoteIP); //目的地的ip
    Int32 lhost= inet_addr(localIP); //本地服务器的ip try
    {
    Byte[] macinfo=new Byte[6];

    IntPtr mac=new IntPtr(macinfo[0]);
    IntPtr len=new IntPtr(6);
    int ii=SendARP(ldest, lhost, macinfo, ref len); return BitConverter.ToString(macinfo);
    }
    catch//(Exception err)
    {
    return string.Empty;
    }

    //return string.Empty;
    }[DllImport("iphlpapi.dll", ExactSpelling=true)]
    public static extern int SendARP( Int32 DestIP, Int32 SrcIP,[Out] byte[] pMacAddr, ref IntPtr PhyAddrLen );[DllImport("Ws2_32.dll", CharSet=CharSet.Ansi)]
    public static extern int inet_addr( string ip );
    调用:
    Console.WriteLine(GetRemoteMAC("192.168.0.1", "192.168.0.42"));仅限于同一网关内