There are a lot of methods, and there is a lot of trouble with simplicity. I chose a lot of trouble here.
Main Code:
Private void getxx (){
RegistryKey start = Registry. LocalMachine;
RegistryKey cardServiceName, networkKey;
String networkcardKey = "SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ NetworkCards ";
String serviceKey = "SYSTEM \ CurrentControlSet \ Services \";
String networkcardKeyName, deviceName;
String deviceServiceName, serviceName;
RegistryKey serviceNames = start. OpenSubKey (networkcardKey );
If (serviceNames = null)
{
MessageBox. Show ("Bad registry key ");
Return;
}
String [] networkCards = serviceNames. GetSubKeyNames ();
ServiceNames. Close ();
Foreach (string keyName in networkCards)
{
NetworkcardKeyName = networkcardKey + "\" + keyName;
CardServiceName = start. OpenSubKey (networkcardKeyName );
If (cardServiceName = null)
{
MessageBox. Show (networkcardKeyName );
Return;
}
DeviceServiceName = (string) cardServiceName. GetValue ("ServiceName ");
DeviceName = (string) cardServiceName. GetValue ("Description ");
MessageBox. Show (deviceName );
ServiceName = serviceKey + deviceServiceName + "\ Parameters \ Tcpip ";
NetworkKey = start. OpenSubKey (serviceName );
If (networkKey = null)
{
......
}
Else
{
String [] ipaddresses = (string []) networkKey. GetValue ("IPAddress ");
String [] defaultGateways = (string []) networkKey. GetValue ("DefaultGateway ");
String [] subnetmasks = (string []) networkKey. GetValue ("SubnetMask ");
Foreach (string ipaddress in ipaddresses)
{
MessageBox. Show (ipaddress );
}
Foreach (string subnetmask in subnetmasks)
{
......}
Foreach (string defaultGateway in defaultGateways)
{
MessageBox. Show (defaultGateway );
}
NetworkKey. Close ();
}
}
Start. Close ();
}