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

  • 相关阅读:
    hadoop生态--ElasticSearch--ES操作
    Haoop生态--ElasticSeaarch(1)--ES预备知识(全文检索的概念、Lucence、倒排索引)
    hadoop生态--Hive(2)--Hive的使用方式
    hadoop生态--Zookeeper
    gsoap使用
    set容器
    如何杀死defunct进程
    关于多态
    数组类型与函数指针基本语法知识
    syslog日志
  • 原文地址:https://www.cnblogs.com/lsysunbow/p/2782908.html
Copyright © 2011-2022 走看看