用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

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

时间:2015-01-29  来源:互联网  作者:佚名
复制代码 代码如下:
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.Success)
            {
                return mc.Groups["key"].Value;
           }
            else
           {
                reg=new Regex("Host not found",RegexOptions.IgnoreCase|RegexOptions.Compiled);
                mc=reg.Match(dirResults);
            if(mc.Success)
            {
                 return "Host not found!";
            }
            else
            {
                 return "";
            }
       }
  }
}
来顶一下
返回首页
返回首页
推荐资讯
深入解析.NET 许可证编译器 (Lc.exe) 的原理与源代码剖析 深入解析.NET 许可证编译器 (Lc.ex在使用第三方类库时,经常会看到它自带的演示程序中,包含有
Asp.net FileUpload+Image制作头像效果示例代码 Asp.net FileUpload+Image制作头像在Web开发中会经常使用到个人信息注册,而个人信息中通常需要
相关文章
栏目更新
栏目热门