ASP.Net获取客户端网卡MAC的小例子

网络编程 2021-07-04 22:40www.168986.cn编程入门
这篇文章介绍了ASP.Net获取客户端网卡MAC的小例子,有需要的朋友可以参考一下
代码如下:

using System.Text.RegularExpressions;
using System.Diagnostics;
public class test
{
        public test
        {}
        public static string GetCustomerMac(string IP) //para IP is the clients 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();
               dirResults=dirResults.Replace(" ","").Replace(" ","").Replace(" ","");
              Regex reg=new Regex("Mac[ ]{0,}Address[ ]{0,}=[ ]{0,}(?<key>((.)?)) __MAC",RegexOptions.IgnoreCase|RegexOptions.Compiled);
               Match mc=reg.Match(dirResults+"__MAC");
           if(mc.Suess)
            {
                return mc.Groups["key"].Value;
           }
            else
           {
                reg=new Regex("Host not found",RegexOptions.IgnoreCase|RegexOptions.Compiled);
                mc=reg.Match(dirResults);
            if(mc.Suess)
            {
                 return "Host not found!";
            }
            else
            {
                 return "";
            }
       }
  }
}

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by