Domanda

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.

È stato utile?

Soluzione

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();
        }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top