如何获取客户端系统Mac-id和其他详细信息,如IP地址等

时间:2013-10-08 10:43:19

标签: c# asp.net system mac-address

在Web项目中,我有一个获取本地系统Mac-id和其他值(如processorid等)的页面,因为我使用了下面的代码。它在Localhost的开发过程中完美运行但是当我们已经发布了该网站,现在使用相同的页面来获取详细信息,它正在获取Web服务器的详细信息。是否有任何其他方式来获取本地计算机的详细信息。请提供任何帮助。

我用于获取系统详细信息的代码是,

  #region Sytem Details
    private string GetMac()
    {
        string Mac = string.Empty;
        ManagementClass MC = new ManagementClass("Win32_NetworkAdapter");
        ManagementObjectCollection MOCol = MC.GetInstances();
        foreach (ManagementObject MO in MOCol)
            if (MO != null)
            {
                if (MO["MacAddress"] != null)
                {
                    Mac = MO["MACAddress"].ToString();
                    if (Mac != string.Empty)
                        break;
                }
            }
        return Mac;
    }



    public static string LocalIPAddress()
    {
        IPHostEntry host;
        string localIP = "";
        host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (IPAddress ip in host.AddressList)
        {
            if (ip.AddressFamily.ToString() == "InterNetwork")
            {
                localIP = ip.ToString();
            }
        }
        return localIP;
    }



    private static string GetProcessorName()
    {

        ManagementClass mgt = new ManagementClass("Win32_Processor");
        ManagementObjectCollection procs = mgt.GetInstances();
        foreach (ManagementObject item in procs)
            return item.Properties["Name"].Value.ToString();

        return "Unknown";
    }



    private string GetProcessorID()
    {
        string sCpuInfo = String.Empty;
        bool bSuccess = false;

        //*** Declare Management Class
        ManagementClass clsMgtClass = new ManagementClass("Win32_Processor");
        ManagementObjectCollection colMgtObjCol = clsMgtClass.GetInstances();

        //*** Loop Over Objects
        foreach (ManagementObject objMgtObj in colMgtObjCol)
        {
            //*** Only return cpuInfo from first CPU
            if (sCpuInfo == String.Empty)
            {
                sCpuInfo = objMgtObj.Properties["ProcessorId"].Value.ToString();
                bSuccess = true;
            }
        }
        if (bSuccess == true)
        {

        }
        return sCpuInfo;
    }



    private static string GetName()
    {
        string netBiosName = System.Environment.MachineName;

        //return netBiosName;
        // Following method is deprecated
        // string dnsName =
        //     System.Net.Dns.GetHostByName("LocalHost").HostName;

        string dnsName = System.Net.Dns.GetHostName();
        return dnsName;
    }



    private string GetOSName()
    {
        System.OperatingSystem os = System.Environment.OSVersion;
        string osName = "Unknown";


        switch (os.Platform)
        {
            case System.PlatformID.Win32Windows:
                switch (os.Version.Minor)
                {
                    case 0:
                        osName = "Windows 95";
                        break;
                    case 10:
                        osName = "Windows 98";
                        break;
                    case 90:
                        osName = "Windows ME";
                        break;
                }
                break;
            case System.PlatformID.Win32NT:
                switch (os.Version.Major)
                {
                    case 3:
                        osName = "Windws NT 3.51";
                        break;
                    case 4:
                        osName = "Windows NT 4";
                        break;
                    case 5:
                        if (os.Version.Minor == 0)
                            osName = "Windows 2000";
                        else if (os.Version.Minor == 1)
                            osName = "Windows XP";
                        else if (os.Version.Minor == 2)
                            osName = "Windows Server 2003";
                        else if (os.Version.Minor == 3)
                            osName = "Windows Vista";
                        else if (os.Version.Minor == 4)
                            osName = "Windows 7";
                        break;
                    case 6:
                        osName = "Windows 8";
                        break;


                }
                break;
        }

        return osName;

    }
    #endregion

修改

它可能不是通过互联网,因为用户将注册系统,所以他/她只获取详细信息和注册,所以有没有任何方法可以自动获取用户的PC数据只需点击一下一个按钮。

1 个答案:

答案 0 :(得分:4)

在Internet上,如果设备/系统位于网络中的路由器后,您无法获取客户端计算机的Mac地址,但如果您的应用程序是Intranet应用程序,则可以先获取客户端的IP地址,然后应用ARP获取客户端设备/机器的mac ID。我已经为我的一个项目做了这个以获取客户端设备的mac ID,但我已经使用了DHCP读取。