获取客户端的MAC地址

    技术2022-05-11  70

    using System.Text.RegularExpressions;   using System.Diagnostics;     /// 获取客户端本地MAC   /// CODE CREATE BY BANLAO   /// </summary>   /// <param name="strIP"> 客户端的IP</param>   /// <returns></returns>    public string _GetCustomerMac( string strIP)   {         string strResults = "";        ProcessStartInfo psi = new ProcessStartInfo();        Process proc = new Process();        psi.FileName = "nbtstat";        psi.RedirectStandardInput = false;        psi.RedirectStandardOutput = true;        psi.Arguments = "-a " + strIP;        psi.UseShellExecute = false;        proc = Process.Start(psi);        strResults = proc.StandardOutput.ReadToEnd();        proc.WaitForExit();

     

           //匹配mac地址       Match m = Regex.Match(strResults, "//w+//-//w+//-//w+//-//w+//-//w+//-//w//w");

           //若匹配成功则返回mac,否则返回找不到主机信息       if (m.ToString() != "")       {            return m.ToString();       }       else       {            return "";       }  }


    最新回复(0)