public DeviceDTOResponse GetDeviceInfo() { DeviceDTOResponse device = new DeviceDTOResponse(); try { ManagementClass mc = new ManagementClass("Win32_ComputerSystemProduct"); foreach (ManagementObject obj in mc.GetInstances()) { device.Label = GetValueAsString(obj, "Name"); device.Sn = GetValueAsString(obj, "IdentifyingNumber"); device.Caption = GetValueAsString(obj, "Caption"); device.Vendor = GetValueAsString(obj, "Vendor"); device.Version = GetValueAsString(obj, "Version"); break; } } catch (ManagementException e) { Logger.Instance.LogError(e.ToString()); } return(device); }
public static void Main(string[] args) { Detector d = new Detector(); Console.WriteLine("Detected CPUs:"); foreach (ProcessorDTOResponse item in d.GetProcessorsInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected memory:"); foreach (MemoryDTOResponse item in d.GetMemoryInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected OS:"); OperatingSystemDTOResponse os = d.GetOperatingSystemInfo(); PropertiesPrinter.Print(os); Console.WriteLine("\nDetected storage:"); foreach (StorageDTOResponse item in d.GetStorageInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected ethernets:"); foreach (EthernetDTOResponse item in d.GetEthernetInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected fc cards:"); foreach (FibreChannelDTOResponse item in d.GetFibreChannelInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected shares:"); foreach (DiskShareMountDTOResponse item in d.GetDiskShareMountInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected software:"); foreach (SoftwareDTOResponse item in d.GetSoftwareInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected device:"); DeviceDTOResponse dev = d.GetDeviceInfo(); PropertiesPrinter.Print(dev); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
public string GetAllComponentsJSON() { string json = "{\"data\":{"; json += "\"status\":\"success\","; json += "\"date\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\","; json += "\"plugin\":\"donpedro\","; json += "\"messages\":[],"; json += "\"device\":{"; DeviceDTOResponse deviceInfo = GetDeviceInfo(); json += "\"model_name\":\"" + deviceInfo.ModelName + "\","; json += "\"serial_number\":\"" + deviceInfo.SerialNumber + "\","; json += "\"system_ip_addresses\":[" + string.Join(",", GetIPAddressInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],"; json += "\"mac_addresses\":[" + string.Join(",", GetMacAddressInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],"; json += "\"disks\":[" + string.Join(",", GetStorageInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],"; json += "\"fibrechannel_cards\":[" + string.Join(",", GetFibreChannelInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],"; json += "\"disk_shares\":[" + string.Join(",", GetDiskShareMountInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],"; json += "\"memory\":[" + string.Join(",", GetMemoryInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],"; json += "\"processors\":[" + string.Join(",", GetProcessorsInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],"; json += "\"installed_software\":[" + string.Join(",", GetSoftwareInfo().ConvertAll(s => s.ToJSON()).ToArray()) + "],"; OperatingSystemDTOResponse operatingSystem = GetOperatingSystemInfo(); json += "\"system_memory\":\"" + operatingSystem.SystemMemory + "\","; json += "\"system_storage\":\"" + operatingSystem.SystemStorage + "\","; json += "\"system_cores_count\":\"" + operatingSystem.SystemCoresCount + "\""; json += "},"; json += "\"results_priority\":{"; json += "\"model_name\":25,"; json += "\"serial_number\":20,"; json += "\"system_ip_addresses\":60,"; json += "\"mac_addresses\":50,"; json += "\"disks\":30,"; json += "\"fibrechannel_cards\":60,"; json += "\"disk_shares\":30,"; json += "\"memory\":60,"; json += "\"processors\":60,"; json += "\"installed_software\":60,"; json += "\"system_memory\":60,"; json += "\"system_storage\":30,"; json += "\"system_cores_count\":60"; return(json + "}}}"); }
public static void Main(string[] args) { Detector d = new Detector(); Console.WriteLine("Detected CPUs:"); foreach (ProcessorDTOResponse item in d.GetProcessorsInfo()) { foreach (var prop in item.GetType().GetProperties()) { Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null)); } Console.WriteLine(); } Console.WriteLine("\nDetected memory:"); foreach (MemoryDTOResponse item in d.GetMemoryInfo()) { foreach (var prop in item.GetType().GetProperties()) { Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null)); } Console.WriteLine(); } Console.WriteLine("\nDetected OS:"); OperatingSystemDTOResponse os = d.GetOperatingSystemInfo(); foreach (var prop in os.GetType().GetProperties()) { Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(os, null)); } Console.WriteLine(); Console.WriteLine("\nDetected storage:"); foreach (StorageDTOResponse item in d.GetStorageInfo()) { foreach (var prop in item.GetType().GetProperties()) { Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null)); } Console.WriteLine(); } Console.WriteLine("\nDetected ethernets:"); foreach (EthernetDTOResponse item in d.GetEthernetInfo()) { foreach (var prop in item.GetType().GetProperties()) { Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null)); } Console.WriteLine(); } Console.WriteLine("\nDetected fc cards:"); foreach (FibreChannelDTOResponse item in d.GetFibreChannelInfo()) { foreach (var prop in item.GetType().GetProperties()) { Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null)); } Console.WriteLine(); } Console.WriteLine("\nDetected shares:"); foreach (DiskShareMountDTOResponse item in d.GetDiskShareMountInfo()) { foreach (var prop in item.GetType().GetProperties()) { Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(item, null)); } Console.WriteLine(); } Console.WriteLine("\nDetected device:"); DeviceDTOResponse dev = d.GetDeviceInfo(); foreach (var prop in dev.GetType().GetProperties()) { Console.WriteLine("\t{0}: {1}", prop.Name, prop.GetValue(dev, null)); } Console.WriteLine(); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
public void Print(Detector d, bool jsonOnly) { if (jsonOnly) { Console.WriteLine(d.GetAllComponentsJSON()); } else { Console.WriteLine("Detected CPUs:"); foreach (ProcessorDTOResponse item in d.GetProcessorsInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected memory:"); foreach (MemoryDTOResponse item in d.GetMemoryInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected OS:"); OperatingSystemDTOResponse os = d.GetOperatingSystemInfo(); PropertiesPrinter.Print(os); Console.WriteLine("\nDetected storage:"); foreach (StorageDTOResponse item in d.GetStorageInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected IP addresses:"); foreach (IPAddressDTOResponse item in d.GetIPAddressInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected MAC addresses:"); foreach (MacAddressDTOResponse item in d.GetMacAddressInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected fc cards:"); foreach (FibreChannelDTOResponse item in d.GetFibreChannelInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected shares:"); foreach (DiskShareMountDTOResponse item in d.GetDiskShareMountInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected software:"); foreach (SoftwareDTOResponse item in d.GetSoftwareInfo()) { PropertiesPrinter.Print(item); } Console.WriteLine("\nDetected device:"); DeviceDTOResponse dev = d.GetDeviceInfo(); PropertiesPrinter.Print(dev); } }