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

    }


  • 相关阅读:
    RSS简易阅读器vb.net源代码
    [建议]有关图片地址的建议
    [音乐欣赏]wind flowers
    有个叫计算机的比我笨
    一个朋友画的建筑设计手绘图与其想到的
    [推荐]华建小翻--QQ里的一个不错的服务商
    爆强的广告
    [学习日记]重构简易RSSREADER的UML类图
    [音乐欣赏]红颜
    [音乐欣赏]花与琴的流星
  • 原文地址:https://www.cnblogs.com/studio313/p/229631.html
Copyright © 2011-2022 走看看