0

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.

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

Edit

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.

Rajesh
  • 1,600
  • 5
  • 33
  • 59
  • I don't think it's possible to detect the mac address of a visitor of your web page, especially if he uses a router or a proxy server (which most users do). – FallenSquirrel Oct 08 '13 at 10:48
  • @FallenSquirrel I am not going to Log the Mac-Id of the Visitor of my Page,the User of My Page has to Register his PC before some actions so for that he can enter the page of Registration and click Getdetails button and Register his PC – Rajesh Oct 08 '13 at 10:54
  • I'm not saying that it would be bad if you log it, I'm just saying that it's simply not possible. To detect the MAC address from the network packages, you have to be in the same LAN as the client, which you are not if you are a webserver. The only other method would be running client side code, like Javascript, which normally cannot access much about the client due to security restrictions (see here: http://stackoverflow.com/questions/4467905/getting-mac-address-on-a-web-page-using-a-java-applet) – FallenSquirrel Oct 11 '13 at 11:16

1 Answers1

4

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.

Rahul Patel
  • 500
  • 3
  • 11
  • Is it Possible to Make the User getting the details automatically and registering from his end – Rajesh Oct 08 '13 at 10:57
  • Or if Its a website to be accessed on windows. you can use silverlight and ask your user for an out of browser with elevated trust – Rahul Patel Oct 08 '13 at 11:02
  • ya the PC will be with Windows OS only,and I dont know what is **browser with elevated trust** could you kindly Explain it or Provide a link where I can get to Know about it. – Rajesh Oct 08 '13 at 11:21
  • A silverlight code runs on client machine instead of server. so you can use your above code to get the Client Mac ID. but when running a SilverLight code from browser you wont get enough permission. to achieve that you need to make it run "Out of Browser" with "elevated trust" find more details here http://msdn.microsoft.com/en-us/library/dd550721(v=vs.95).aspx – Rahul Patel Oct 08 '13 at 12:06