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


  • 相关阅读:
    静态方法、类方法、属性方法
    B-tree/B+tree
    支付宝
    七牛云上传视频3
    测试理论
    测试理论
    Xshell上传文件
    iptables增加、删除、修改、查询、保存防火墙策略教程
    docker私有仓库常用命令
    centos7修改主机名
  • 原文地址:https://www.cnblogs.com/winner/p/743601.html
Copyright © 2011-2022 走看看