zoukankan      html  css  js  c++  java
  • .Net获取远程mac地址


            /// <summary>
            /// 获取mac地址
            /// </summary>
            /// <returns></returns>
            private string GetMac()
            {
                string MAC = "";
                ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection MOC = MC.GetInstances();
                foreach (ManagementObject moc in MOC)
                {
                    if (moc["IPEnabled"].ToString() == "True")
                    {
                        MAC = moc["MacAddress"].ToString();
                    }
                }
                return MAC;
            }
            public string GetCustomerMac(string IP) //para IP is the client's IP
            {
                if (IP == "127.0.0.1")
                {
                    return GetMac();
                }//"00-04-61-5C-31-52";//00-0F-1F-C6-B2-B3
                else
                {
                    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", "");
                    int i = dirResults.LastIndexOf("=");
                    dirResults = dirResults.Substring(i + 2, 17);
                    if (dirResults.IndexOf("本地连接") != -1)
                    { dirResults = "没有得到mac"; }
                    return dirResults;
                }
            }

  • 相关阅读:
    C++ 沉思录——Chap6:句柄2
    C++ 沉思录——Chap5:代理类
    C++ 沉思录——Chap4:设计类的核查表
    Linux 网卡驱动相关——01
    FCoE的提出
    想成为嵌入式程序员应知道的0x10个基本问题
    C++ 沉思录——Chap6:句柄
    C++ 沉思录——Chap8:一个面向对象程序范例
    数据库调优积累系列(1):索引
    QTP使用问题集锦
  • 原文地址:https://www.cnblogs.com/lsysunbow/p/2782908.html
Copyright © 2011-2022 走看看