• .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 client's 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("\r","").Replace("\n","").Replace("\t","");

                  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 ""; 
                } 
           }
      }
    }


  • 相关阅读:
    【halcon】学习记录
    【QT】常用类
    【QT】宏
    机器视觉名词解释
    单元测试
    【MFC】VS2017新建完MFC后,没有界面,只有代码
    【MFC】学习与问题整合
    函数重载(overload)和函数重写(override)
    工作记录+反思
    【转】MapReduce:默认Counter的含义
  • 原文地址:https://www.cnblogs.com/winner/p/743601.html
Copyright © 2020-2023  润新知