문제

I know how to get the serial number of a mac computer using objective c but wondered if there was a way using c# (mono)?

Obviously this is to uniquely identify a machine. I am already using the MAC address but need something which can't be spoofed.

도움이 되었습니까?

해결책

THe following should give you the serial number. Though it is not purely via mono. But this should work.

       string serialNumber;
        using (var p = new Process())
        {
            var serialRegex = new Regex("\"IOPlatformSerialNumber\" = \"(\\S+)\"");
            p.StartInfo = new ProcessStartInfo("/usr/sbin/ioreg",
                                               "-c IOPlatformExpertDevice");
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();
            serialNumber = serialRegex.Match(p.StandardOutput.ReadToEnd()).Groups[1].Captures[0].Value;
            p.WaitForExit();
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top