Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Hard Disks");
            var hds = HardDrive.Discover();

            foreach (var hd in hds)
            {
                Console.WriteLine($"{hd.Name} {hd.Identifier}");
            }

            var identity = ComputerIdentity.Collect();

            Console.WriteLine(identity.MachineName);

            Console.WriteLine();
            if (identity.Os != null)
            {
                Console.WriteLine("OS:");
                Console.WriteLine(identity.Os.Name);
                Console.WriteLine(identity.Os.Version);
            }

            Console.WriteLine();
            if (identity.Board != null)
            {
                Console.WriteLine("Board:");
                Console.WriteLine(identity.Board.Name);
                Console.WriteLine(identity.Board.Model);
                Console.WriteLine(identity.Board.Manufacturer);
                Console.WriteLine(identity.Board.SerialNumber);
            }

            Console.WriteLine();
            if (identity.Cpus != null)
            {
                Console.WriteLine("CPUs:");
                foreach (var cpu in identity.Cpus)
                {
                    Console.WriteLine($"{cpu.Name} {cpu.Vendor} {cpu.Identifier}");
                }
            }

            Console.WriteLine();
            if (identity.NetworkInterfaces != null)
            {
                Console.WriteLine("Network Interfaces:");
                foreach (var ni in identity.NetworkInterfaces)
                {
                    Console.WriteLine($"{ni.PhysicalAddress} {ni.Name} {ni.Id}");
                }
            }

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public static ComputerIdentity Collect()
        {
            var mainboard         = new Mainboard();
            var cpus              = Cpu.Discover();
            var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();

            var identity = new ComputerIdentity()
            {
                MachineName = Environment.MachineName,
                Os          = new OsIdentity
                {
                    Name    = Environment.OSVersion.Platform.ToString(),
                    Version = Environment.OSVersion.VersionString,
                },
                Board = new BoardIdentity
                {
                    Name         = mainboard.Name,
                    Model        = mainboard.Model.ToString(),
                    Manufacturer = mainboard.Manufacturer.ToString(),
                    SerialNumber = mainboard.Smbios?.Board?.SerialNumber
                },
                Cpus = (from cpu in cpus
                        select new CpuIdentity
                {
                    Name = cpu.Name,
                    Identifier = cpu.Identifier,
                    Vendor = cpu.Vendor
                }).ToArray(),
                NetworkInterfaces = (from ni in networkInterfaces
                                     where ni.OperationalStatus == OperationalStatus.Up
                                     let physicalAddress = ni.GetPhysicalAddress()?.ToString()
                                                           where !string.IsNullOrWhiteSpace(physicalAddress)
                                                           select new NetworkInterfaceIdentity
                {
                    Name = ni.Name,
                    Id = ni.Id,
                    Type = ni.NetworkInterfaceType.ToString(),
                    PhysicalAddress = physicalAddress
                }).ToArray()
            };

            return(identity);
        }