C SharP中,获得了客户端的IP后,该如何获取其MAC地址
谢谢~~~~~~~~~~~~~~~~~~~

解决方案 »

  1.   

    是在server端获取client端的mac地址,还是client端获取本机的mac地址如果是后者,可以参看
    http://www.codeproject.com/csharp/host_info_within_network.asp
      

  2.   

    前者是不可能的,除非client端告知。
      

  3.   

    哦!!
    我是想获取Client端的MAC地址!
    真的不行啊,我想是否可由IP地址映射到其MAC地址~~~~~~~~~~
    那该如何获取其Mac,难道要分析其帧,是否太麻烦了???
      

  4.   

    to 真的不行啊,我想是否可由IP地址映射到其MAC地址不可能,除非你服务器有IP与Mac之间的对应关系。
      

  5.   

    IP包头中包括客户端的 Mac 地址,具体可参见 IP 头结构
      

  6.   

    可以获取MAC吧。有一款软件“网络剪刀手"NetCut可以获取局域网所有电脑的MAC
      

  7.   

    用这个去获取,没问题.
    nbtstat -A xxx.xxx.xxx.xxx
      

  8.   

    还可用这个API函数.[DllImport("Iphlpapi.dll")] 
    private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length);
      

  9.   

    我没找到这个API函数,可否帮我解释一下函数的参数,及其返回值
    谢谢~~~~~~~~~
      

  10.   

    参见:http://spaces.msn.com/cloudhuhu/Blog/cns!1pGWJrG_igtoCGSKMmhnpk-g!116.entry使用SendARP获取MAC using System.Runtime.InteropServices;
    using System.Text.RegularExpressions;
    using System.Text;
     [DllImport("Iphlpapi.dll")]
    private static unsafe extern int SendARP(Int32 dest,Int32 host,ref Int32 mac,ref Int32 length);[DllImport("Ws2_32.dll")]
    private static extern Int32 inet_addr(string ip);public string GetMACFromIP(string A_strIP)
    {
      string strRet = "Unknown";
      string strIPPattern = @"^\d+\.\d+\.\d+\.\d+$";  Regex objRex =new Regex(strIPPattern);
      if(objRex.IsMatch(A_strIP) == true)
      {
        Int32 intDest = inet_addr(A_strIP);
        Int32 [] arrMAC = new Int32[2];
        Int32 intLen = 6;
        int intResult = SendARP(intDest,0,ref arrMAC[0],ref intLen);
        if(intResult == 0)
        {
          Byte [] arrbyte = new Byte[8];
          arrbyte[5] = (Byte)(arrMAC[1] >> 8);
          arrbyte[4] = (Byte)arrMAC[1];
          arrbyte[3] = (Byte)(arrMAC[0] >> 24);
          arrbyte[2] = (Byte)(arrMAC[0] >> 16);
          arrbyte[1] = (Byte)(arrMAC[0] >> 8);
          arrbyte[0] = (Byte)arrMAC[0];      StringBuilder strbMAC = new StringBuilder(); 
          for(int intIndex = 0 ;intIndex < 6;intIndex ++)
          {
            if(intIndex > 0) strbMAC.Append("-");
            strbMAC.Append(arrbyte[intIndex].ToString("X2"));
          }
          strRet = strbMAC.ToString();
        }
      }return strRet;
    }
      

  11.   

    局域网里面的机器可以获得MAC
    公网的基本别想了,路由器不会转发这些数据的
      

  12.   

    public static string GetMAC(string clientip)
    {
    string mac="";
    System.Diagnostics.Process process=new System.Diagnostics.Process();
    process.StartInfo.FileName="nbtstat";
    process.StartInfo.Arguments="-a "+clientip;
    process.StartInfo.UseShellExecute=false;
    process.StartInfo.CreateNoWindow=true;
    process.StartInfo.RedirectStandardOutput=true;
    process.Start();
    string output=process.StandardOutput.ReadToEnd();
    int length=output.IndexOf("MAC Address =");
    if(length>0)
    {
    mac=output.Substring(length+14,17);
    }
    return mac;
    }
      

  13.   

    try:Process p = new Process();
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;p.Start();
    p.StandardInput.WriteLine("nbtstat -A 192.168.xx.xx");
    p.StandardInput.WriteLine("exit");string s = "";while((s = p.StandardOutput.ReadLine()) != null)
    {
        if(s.Contains("MAC"))
        {
            Console.WriteLine(s);
        }
    }
      

  14.   

    insiderc() 
    强~
    感谢