如何获得客户端系统MAC-ID和其他细节,如IP地址等 [英] How to get the Client System Mac-id and other details like IP Address etc

查看:126
本文介绍了如何获得客户端系统MAC-ID和其他细节,如IP地址等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Web项目我有一个网页,其中获取本地系统MAC-ID以及诸如processorid等其他值,我已经使用了低于code.It在本地主机但是,当我们已经公布了网站,现在使用相同的页面获取的细节,这是获取网络Server.Is有细节的任何替代方法来获取本地计算机details.Kindly任何一个帮助。

In web project I have a Page which fetches the Local System Mac-id and other values such as processorid etc,for that I have used the below code.It worked perfectly during Development in the Localhost but when we had published the website and now use the same page to fetch the details,it is fetching the details of the Web Server.Is there any alternate way to fetch the Local Machines details.Kindly any one help.

在code我UED的抓取系统的细节是,

The code I ued for Fetching System details is,

  #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

修改

这可能不是在互联网上,因为用户要注册系统,让他/她只得到细节和寄存器,所以有从他结束时自动获得在短短的点击用户电脑数据的方式的按钮。

It may not be over the Internet because the User is going to register the System,so he/she only gets the details and registers,so is there any way of Automatically getting the users PC data from his end in Just a Click of a button.

推荐答案

在互联网如果该设备/系统自带的网络路由器后无法获取客户机的MAC地址,但如果您的应用程序是一个Intranet应用你可以先拿到客户端的IP地址,然后申请一个ARP来获得客户端设备/机器的MAC ID。我这样做对我的项目,得到客户的设备的MAC ID之一,但我已经使用读取一个相同的DHCP。

Over Internet you can't fetch Mac Address of client machine if the device/system comes after a router in Network, though if your application is an Intranet application you can first get the IP address of client and then apply an ARP to get the mac ID of client device/machine. I have done this for one of my projects to get the mac ID of client's device but I have used a DHCP read for the same.

这篇关于如何获得客户端系统MAC-ID和其他细节,如IP地址等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆