1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
// Filename: HardwareInfo.cs
// Contains functions to extract information displayed in Hardware category
using System;
using System.IO;
using System.Diagnostics;
using System.Collections;
namespace Sysinfo {
public class HardwareInfo {
public String [] host_bridge = {null, null};
public ArrayList pci_bridge = new ArrayList();
public ArrayList usb_controller = new ArrayList();
public String [] isa_bridge = {null, null};
public String [] ide_interface = {null, null};
public String [] vga_controller = {null, null};
public String [] multimedia_controller = {null, null};
public String [] network_controller = {null, null};
public String [] ethernet_controller = {null, null};
public String [] modem = {null, null};
String path = "lspci";
public HardwareInfo() {
//lspci path
if ( File.Exists( "/usr/sbin/lspci") )
path = "/usr/sbin/lspci";
if ( File.Exists( "/sbin/lspci") )
path = "/sbin/lspci";
if ( File.Exists( "/bin/lspci") )
path = "/bin/lspci";
if ( File.Exists( "/usr/bin/lspci") )
path = "/usr/bin/lspci";
}
//all static info
public void StaticInfo() {
String temp;
Boolean host_bridgeB = false;
Int32 pci_bridgeI = 0;
Int32 usb_controllerI = 0;
Boolean isa_bridgeB = false;
Boolean ide_interfaceB = false;
Boolean vga_controllerB = false;
Boolean multimedia_controllerB = false;
Boolean network_controllerB = false;
Boolean ethernet_controllerB = false;
Boolean modemB = false;
try {
//run lspci command and read output
Process proc1 = new Process();
proc1.StartInfo.FileName = path;
proc1.StartInfo.Arguments = "-v";
proc1.StartInfo.UseShellExecute = false;
proc1.StartInfo.RedirectStandardOutput = true;
proc1.Start();
proc1.WaitForExit();
while ( proc1.StandardOutput.Peek() != (-1) ) {
temp = proc1.StandardOutput.ReadLine();
/* Motherboard */
//host bridge
if ( temp.Length <= 1 )
host_bridgeB = false;
if ( host_bridgeB && temp.StartsWith("\tSubsystem") ) {
host_bridge [1] = temp.Remove(0, temp.IndexOf(" ") + 1);
host_bridgeB = false;
}
if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("Host bridge") ) {
host_bridge [0] = temp.Remove(0, temp.IndexOf(" ") + 14);
host_bridgeB = true;
}
//pci bridge
if (temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("PCI bridge")) {
pci_bridge.Add(temp.Remove(0, temp.IndexOf(" ") + 13));
pci_bridgeI++;
}
//usb controller
if (temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("USB Controller")) {
usb_controller.Add(temp.Remove(0, temp.IndexOf(" ") + 17));
usb_controllerI++;
}
//isa bridge
if ( temp.Length <= 1 )
isa_bridgeB = false;
if ( isa_bridgeB && temp.StartsWith("\tSubsystem") ) {
isa_bridge [1] = temp.Remove(0, temp.IndexOf(" ") + 1);
isa_bridgeB = false;
}
if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("ISA bridge") ) {
isa_bridge [0] = temp.Remove(0, temp.IndexOf(" ") + 13);
isa_bridgeB = true;
}
//ide interface
if ( temp.Length <= 1 )
ide_interfaceB = false;
if ( ide_interfaceB && temp.StartsWith("\tSubsystem") ) {
ide_interface [1] = temp.Remove(0, temp.IndexOf(" ") + 1);
ide_interfaceB = false;
}
if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("IDE interface") ) {
ide_interface [0] = temp.Remove(0, temp.IndexOf(" ") + 16);
ide_interfaceB = true;
}
/* Graphic card */
//vga compatible controller
if ( temp.Length <= 1 )
vga_controllerB = false;
if ( vga_controllerB && temp.StartsWith("\tSubsystem") ) {
vga_controller [1] = temp.Remove(0, temp.IndexOf(" ") + 1);
vga_controllerB = false;
}
if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("VGA compatible controller") ) {
vga_controller [0] = temp.Remove(0, temp.IndexOf(" ") + 28);
vga_controllerB = true;
}
/* Sound card */
//multimedia audio controller
if ( temp.Length <= 1 )
multimedia_controllerB = false;
if ( multimedia_controllerB && temp.StartsWith("\tSubsystem") ) {
multimedia_controller [1] = temp.Remove(0, temp.IndexOf(" ") + 1);
multimedia_controllerB = false;
}
if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("Multimedia audio controller") ) {
multimedia_controller [0] = temp.Remove(0, temp.IndexOf(" ") + 30);
multimedia_controllerB = true;
}
else if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("Audio device") ) {
multimedia_controller [0] = temp.Remove(0, temp.IndexOf(" ") + 15);
multimedia_controllerB = true;
}
/* Network devices */
//network controller
if ( temp.Length <= 1 )
network_controllerB = false;
if ( network_controllerB && temp.StartsWith("\tSubsystem") ) {
network_controller [1] = temp.Remove(0, temp.IndexOf(" ") + 1);
network_controllerB = false;
}
if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("Network controller") ) {
network_controller [0] = temp.Remove(0, temp.IndexOf(" ") + 21);
network_controllerB = true;
}
//ethernet controller
if ( temp.Length <= 1 )
ethernet_controllerB = false;
if ( ethernet_controllerB && temp.StartsWith("\tSubsystem") ) {
ethernet_controller [1] = temp.Remove(0, temp.IndexOf(" ") + 1);
ethernet_controllerB = false;
}
if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("Ethernet controller") ) {
ethernet_controller [0] = temp.Remove(0, temp.IndexOf(" ") + 22);
ethernet_controllerB = true;
}
//modem
if ( temp.Length <= 1 )
modemB = false;
if ( modemB && temp.StartsWith("\tSubsystem") ) {
modem [1] = temp.Remove(0, temp.IndexOf(" ") + 1);
modemB = false;
}
if ( temp.Remove(0, temp.IndexOf(" ") + 1).StartsWith("Modem:") ) {
modem [0] = temp.Remove(0, temp.IndexOf(" ") + 8);
modemB = true;
}
}
proc1.Close();
}
catch (Exception ex) { Console.WriteLine( ex ); }
}
}
}
//ghaefb
|