Reputation: 2393
Anybody knows how to get nic card name
when I do ipconfig/all I can get this
Ethernet adapter XC99HT:
Connection-specific DNS Suffix . : xx.xx.com
Description . . . . . . . . . . . : HP NC382i DP Multifunction Gigabit Server
Adapter
Physical Address. . . . . . . . . : F4-CE-46-94-E8-B0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 177.77.153.48(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 177.77.153.1
DNS Servers . . . . . . . . . . . : 177.77.124.129
177.77.124.130
Primary WINS Server . . . . . . . : 177.77.124.129
Secondary WINS Server . . . . . . : 177.77.124.130
NetBIOS over Tcpip. . . . . . . . : Enabled
would like to get "HP NC382i DP Multifunction Gigabit Server Adapter" just by using/passing the Ethernet name "XC99HT"
Upvotes: 3
Views: 4957
Reputation: 71565
To do this properly from within code, you'll probably want to use WMI. WMI (Windows Management Intrumentation) is a "metadatabase" within Windows that contains information about just about everything that's going on at a device level. You access it using the System.Management namespace in .NET, primarily the ManagementObjectSearcher class. You search WMI using a syntax similar to SQL. Here's a basic query that returns all active network adapters:
select * from Win32_NetworkAdapterConfiguration where IPEnabled = true
Pretty much anything you could see using IPConfig (and more) is available from the resulting ManagementObjectCollection. Unfortunately I don't know what field of the objects would have the data "XC99HT".
Upvotes: 1
Reputation: 327
Something like this?
public static void ShowInterfaceSummary()
{
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in interfaces)
{
Console.WriteLine ("Name: {0}", adapter.Name);
Console.WriteLine(adapter.Description);
Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length,'='));
Console.WriteLine(" Interface type .......................... : {0}", adapter.NetworkInterfaceType);
Console.WriteLine(" Operational status ...................... : {0}",
adapter.OperationalStatus);
string versions ="";
// Create a display string for the supported IP versions.
if (adapter.Supports(NetworkInterfaceComponent.IPv4))
{
versions = "IPv4";
}
if (adapter.Supports(NetworkInterfaceComponent.IPv6))
{
if (versions.Length > 0)
{
versions += " ";
}
versions += "IPv6";
}
Console.WriteLine(" IP version .............................. : {0}", versions);
Console.WriteLine();
}
Console.WriteLine();
}
Upvotes: 9