当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.Net获取客户端网卡MAC的小例子

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

同城知己交友网,神雕外传之郭襄,芯羊

复制代码 代码如下:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网