HELP - enumerating local NICS

  • Thread starter Thread starter LK
  • Start date Start date
L

LK

Can PLEASE SOMEONE HELP me how to enumerate local network interfaces (i.e ip
addresses, dns, etc.) with csharp.

I need the type of information that would come up when typing

ipconfig /all

at a command prompt.

Thank you soo much
 
LK said:
Can PLEASE SOMEONE HELP me how to enumerate local network interfaces (i.e ip
addresses, dns, etc.) with csharp.

I need the type of information that would come up when typing

ipconfig /all

at a command prompt.

Thank you soo much

You could use WMI. Try the following (remember to reference
System.Messaging.dll):

using System;
using System.Management;

public class App
{
public static void Main()
{
ManagementObjectSearcher mos =
new ManagementObjectSearcher("select * from
Win32_NetworkAdapterConfiguration");
ManagementObjectCollection adapters = mos.Get();
foreach(ManagementObject adapter in adapters)
{
String[] ipAddresses = (String[])adapter["IPAddress"];
foreach(String ipAddress in ipAddresses)
Console.WriteLine(ipAddress);
}
}
}

Check out [1] for information about the
Win32_NetworkAdapterConfiguration WMI Class.

/Joakim

[1]
http://msdn.microsoft.com/library/d...sdk/wmi/win32_networkadapterconfiguration.asp
 
Oh, thank you soo much, just what I needed. I suppose that there is nothing
under System.Net that I could use. Just one more question, what does this
mean, and do I have to worry about it when distributing the app to the
general population. Thank you soo much

"The class is not guaranteed to be supported after the ratification of the
Distributed Management Task Force (DMTF) CIM network specification."

Joakim Karlsson said:
LK said:
Can PLEASE SOMEONE HELP me how to enumerate local network interfaces (i.e
ip
addresses, dns, etc.) with csharp.

I need the type of information that would come up when typing

ipconfig /all

at a command prompt.

Thank you soo much

You could use WMI. Try the following (remember to reference
System.Messaging.dll):

using System;
using System.Management;

public class App
{
public static void Main()
{
ManagementObjectSearcher mos =
new ManagementObjectSearcher("select * from
Win32_NetworkAdapterConfiguration");
ManagementObjectCollection adapters = mos.Get();
foreach(ManagementObject adapter in adapters)
{
String[] ipAddresses = (String[])adapter["IPAddress"];
foreach(String ipAddress in ipAddresses)
Console.WriteLine(ipAddress);
}
}
}

Check out [1] for information about the
Win32_NetworkAdapterConfiguration WMI Class.

/Joakim

[1]
http://msdn.microsoft.com/library/d...sdk/wmi/win32_networkadapterconfiguration.asp
 
LK said:
Oh, thank you soo much, just what I needed. I suppose that there is nothing
under System.Net that I could use. Just one more question, what does this
mean, and do I have to worry about it when distributing the app to the
general population. Thank you soo much

The target OS must have WMI installed in order for the System.Management
assembly to work. It is installed by default on Windows 2000 and Windows
ME and later. For Windows 95/98 you can download it here [1].
"The class is not guaranteed to be supported after the ratification of the
Distributed Management Task Force (DMTF) CIM network specification."

I hadn't noticed that comment myself! From what I can see this means
that the schema of this class is subject to change, but there will be
something similar available in the future.

/Joakim

[1]
http://www.microsoft.com/downloads/...BA-337B-4E92-8C18-A63847760EA5&displaylang=en
 
Back
Top