Code Monkey home page Code Monkey logo

ismbios's Introduction


What is iSMBIOS?

iSMBIOS is a lightweight implementation that allows us to obtain the SMBIOS information

This library fully implements DMTF Specification 3.2.0 and olders versions

For more information, please see https://www.dmtf.org/standards/smbios

Install via NuGet

NuGet Version

Usage

Call DMI.Instance.Structures for getting all SMBIOS structures availables.

Examples

  1. Gets and prints all SMBIOS availables structures.

    DmiStructureCollection structures = DMI.Instance.Structures;
    foreach (DmiStructure structure in structures)
    {
        Console.WriteLine($"{(int) structure.Class:D3}-{structure.Class}");
    }
    
  2. Gets a specific SMBIOS structure.

    DmiStructureCollection structures = DMI.Instance.Structures;
    DmiStructure bios = structures[SmbiosStructure.Bios];
    if (bios != null)
    {
        /// structure exist!!!
    }
    
  3. Gets a single property directly.

    DmiStructureCollection structures = DMI.Instance.Structures;
    object biosVersion = structures.GetProperty(DmiProperty.Bios.BiosVersion);
    if (biosVersion != null)
    {
        Console.WriteLine($" BIOS Version > {biosVersion}");
    }
    
    string biosVendor = structures.GetProperty<string>(DmiProperty.Bios.Vendor);
    Console.WriteLine($" > BIOS Vendor > {biosVendor}");
    
    string processorFamily = structures.GetProperty<string>(DmiProperty.Processor.Family);
    Console.WriteLine($" Processor Family > {processorFamily}");
    
    string processorManufacturer = structures.GetProperty<string>(DmiProperty.Processor.ProcessorManufacturer);
    Console.WriteLine($" Processor Manufacturer > {processorManufacturer}");
    
  4. Gets a property in multiple elements directly.

    // Requires that the Slot Information structure exists in your system
    DmiStructureCollection structures = DMI.Instance.Structures;
    IDictionary<int, object> systemSlots = structures.GetProperties(DmiProperty.SystemSlots.SlotId);
    foreach (KeyValuePair<int, object> systemSlot in systemSlots)
    {
        int element = systemSlot.Key;
        object property = systemSlot.Value;
        Console.WriteLine($" System Slot ({element}) > {property}");
    }
    
  5. Prints all SMBIOS structures properties

    DmiStructureCollection structures = DMI.Instance.Structures;
    foreach (DmiStructure structure in structures)
    {
        DmiStructureClass currentClass = structure.Class;
    
        Console.WriteLine();
        Console.WriteLine($" —————————————————————————————————————————— DMI ({DMI.AccessType}) —");
        Console.WriteLine($" {(int)currentClass:D3}-{currentClass} structure detail");
        Console.WriteLine($" ——————————————————————————————————————————————————————————————");
        DmiClassCollection elements = structure.Elements;
        foreach (DmiClass element in elements)
        {
            Hashtable elementProperties = element.Properties;
            foreach (DictionaryEntry property in elementProperties)
            {
                object value = property.Value;
    
                PropertyKey key = (PropertyKey)property.Key;
                Enum id = key.PropertyId;
    
                PropertyUnit valueUnit = key.PropertyUnit;
                string unit =
                    valueUnit == PropertyUnit.None
                        ? string.Empty
                        : valueUnit.ToString();
    
                if (value == null)
                {
                    Console.WriteLine($"{id} > NULL");
                    continue;
                }
    
                if (value is string)
                {
                    Console.WriteLine($"   > {id} > {value} {unit}");
                }
                else if (value is byte)
                {
                    Console.WriteLine($"   > {id} > {value}{unit} [{value:X2}h]");
                }
                else if (value is short)
                {
                    Console.WriteLine($"   > {id} > {value}{unit} [{value:X4}h]");
                }
                else if (value is ushort)
                {
                     Console.WriteLine($"   > {id} > {value}{unit} [{value:X4}h]");
                }
                else if (value is int)
                {
                    Console.WriteLine($"   > {id} > {value} {unit} [{value:X4}h]");
                }
                else if (value is uint)
                {
                    Console.WriteLine($"   > {id} > {value} {unit} [{value:X4}h]");
                }
                else if (value is long)
                {
                    Console.WriteLine($"   > {id} > {value} {unit} [{value:X8}h]");
                }
                else if (value is ulong)
                {
                    Console.WriteLine($"   > {id} > {value} {unit} [{value:X8}h]");
                }
                else if (value.GetType() == typeof(ReadOnlyCollection<byte>))
                {
                    Console.WriteLine($"   > {id} > {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                }
                else if (value.GetType() == typeof(ReadOnlyCollection<string>))
                {
                    Console.WriteLine($"   > {id}");
                    var collection = (ReadOnlyCollection<string>) value;
                    foreach (var entry in collection)
                    {
                        Console.WriteLine($"     > {entry} {unit}");
                    }
                }
                else
                {
                    Console.WriteLine($"   > {id} > {value} {unit}");
                }
            }
        }
    }
    

How can I send feedback!!!

If you have found iSMBIOS useful at work or in a personal project, I would love to hear about it. If you have decided not to use iSMBIOS, please send me and email stating why this is so. I will use this feedback to improve iSMBIOS in future releases.

My email address is [email protected]

ismbios's People

Contributors

iajtin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.