zoukankan      html  css  js  c++  java
  • 用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 ""
                }
     
           }
     
      }

    }


  • 相关阅读:
    Tomcat 容器的安全认证和鉴权
    Tomcat 中的 Session 和 Cookie
    Tomcat 类加载器的实现
    Tomcat 对静态资源的处理
    Tomcat 路由请求的实现 Mapper
    Tomcat 配置文件解析工具 Digester
    Tomcat 容器的设计和实现
    ArrayList 和 LinkedList 源码分析
    Mybatis自定义分布式二级缓存实现与遇到的一些问题解决方案!
    Dubbo序列化多个CopyOnWriteArrayList对象变成同一对象的一个大坑!!
  • 原文地址:https://www.cnblogs.com/studio313/p/229631.html
Copyright © 2011-2022 走看看