首页 > 编程 > .NET > 正文

用ASP.Net获取客户端网卡的MAC

2024-07-10 12:55:48
字体:
来源:转载
供稿:网友

 

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表