Вопрос

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