Pregunta

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.

¿Fue útil?

Solución

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();
        }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top