How to detect the original MAC address after it has been spoofed?

前端 未结 4 822
慢半拍i
慢半拍i 2020-11-28 08:47

We are using the following code for retrieving active MAC address of a windows pc.

private static string macId()
{
    return identifier(\"Win32_NetworkAdapt         


        
4条回答
  •  一生所求
    2020-11-28 09:13

    I wish to give an alternative. I don't know if it really answer to 'a way to uniquely identify any computer'.
    However, this method query the Win32_BIOS class in System.Management and return a string with high chances to be unique. (Waiting to be disavowed!!)

    /// 
    /// BIOS IDentifier
    /// 
    /// 
    public static string BIOS_ID()
    {
        return    GetFirstIdentifier("Win32_BIOS", "Manufacturer")
                + GetFirstIdentifier("Win32_BIOS", "SMBIOSBIOSVersion")
                + GetFirstIdentifier("Win32_BIOS", "IdentificationCode")
                + GetFirstIdentifier("Win32_BIOS", "SerialNumber")
                + GetFirstIdentifier("Win32_BIOS", "ReleaseDate")
                + GetFirstIdentifier("Win32_BIOS", "Version");
    }
    
    /// 
    /// ManagementClass used to read the first specific properties
    /// 
    /// Object Class to query
    /// Property to get info
    /// 
    private static string GetFirstIdentifier(string wmiClass, string wmiProperty)
    {
        string result = string.Empty;
        ManagementClass mc = new System.Management.ManagementClass(wmiClass);
        ManagementObjectCollection moc = mc.GetInstances();
        foreach (ManagementObject mo in moc)
        {
            //Only get the first one
            if (string.IsNullOrEmpty(result))
            {
                try
                {
                    if (mo[wmiProperty] != null) result = mo[wmiProperty].ToString();
                    break;
                }
                catch
                {
                }
            }
        }
        return result.Trim();
    }
    

提交回复
热议问题