Question

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.

Was it helpful?

Solution

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();
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top