获取客户端MAC地址

来源:互联网 发布:java version是什么 编辑:程序博客网 时间:2024/05/17 06:15


using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Net;

 

 

public string GetCustomerMac(string IP)
  {
   string dirResults = "";
   ProcessStartInfo psi = new ProcessStartInfo();
   Process proc = new Process();
   psi.FileName = "nbtstat";
   psi.RedirectStandardInput = false;
   psi.RedirectStandardOutput = true;
   psi.Arguments = "-a " + IP;
   psi.UseShellExecute = false;
   proc = Process.Start(psi);
   dirResults = proc.StandardOutput.ReadToEnd();
   proc.WaitForExit();
 
   //
   Match m = Regex.Match(dirResults, "//w+//-//w+//-//w+//-//w+//-//w+//-//w//w");
 
   //
   if (m.ToString() != "")
   {
    return m.ToString();
   }
   else
   {
    return "找不到主机信息,该用户不在同网段! ";
   }
 
  }