服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - ASP.NET教程 - ASP.Net获取客户端网卡MAC的小例子

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

2019-11-13 11:37asp.net教程网 ASP.NET教程

这篇文章介绍了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.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 ""; 
            } 
       } 
  }
}

延伸 · 阅读

精彩推荐