码迷,mamicode.com
首页 > 其他好文 > 详细

机器码信息

时间:2016-09-18 10:16:26      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

public partial class mac : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            var sb = new System.Text.StringBuilder();
            sb.AppendLine(string.Join("|", GetMacString()));
            sb.AppendLine(GetProcessInfo());
            sb.AppendLine(GetAllProcessInfo());

            Response.Expires = -1;
            Response.Clear();
            Response.ContentEncoding = Encoding.UTF8;
            Response.ContentType = "application/json";
            Response.Write(sb.ToString());
            Response.Flush();
            Response.End();


            base.OnLoad(e);
        }


        public NetworkInterface[] NetCardInfo()
        {
            return NetworkInterface.GetAllNetworkInterfaces();
        }

        public string[] GetMacString()
        {
            string strMac = "";
            NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface ni in interfaces)
            {
                if (ni.OperationalStatus == OperationalStatus.Up)
                {
                    strMac += ni.GetPhysicalAddress().ToString() + "|";
                }
            }
            return strMac.Split(|);
        }

        public string GetProcessInfo()
        {
            var process = Process.GetCurrentProcess();
            var str = process.Id + "|" + process.ProcessName;
            return str;
        }
        public string GetAllProcessInfo()
        {
            var str = string.Empty;
            var processes = Process.GetProcesses().OrderBy(p=>p.Id).ToList();
            foreach (var process in processes)
            {
                str += process.Id + "|" + process.ProcessName + "<br/>" ;
            }
            return str;
        }
    }

 

机器码信息

标签:

原文地址:http://www.cnblogs.com/shiningrise/p/5880345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!