Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What network cards are installed on my computer?
Message
From
24/11/2004 18:11:09
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00963864
Message ID:
00964539
Views:
12
>>Nice Einar,
>>You wouldn't mind me copying this code I hope:)
>>Cetin
>
>Cetin,
>Your request to copy my code has been granted :)
>I did some more digging and found that Win32_NetworkAdapterConfiguration seems to be a bigger class (table) than Win32_NetworkAdapter.
>I have decided to move further with the Win32_NetworkAdapterConfiguration WMI class until I find out otherwise.
>Here is some of my test code that simply displays some of the information I am interested in in a messagebox.
>
>
>System.String sQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'";
>System.String sMsgBoxText= "";
>
>
>System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(sQuery);
>foreach (System.Management.ManagementObject nic in searcher.Get())
>{
>  sMsgBoxText= "";
>  sMsgBoxText = sMsgBoxText + "Caption = " + nic["Caption"] + "\r\n";
>  sMsgBoxText = sMsgBoxText + "Hostname = " + nic["DNSHostName"] + "\r\n";
>  sMsgBoxText = sMsgBoxText + "Description = " + nic["Description"] + "\r\n";
>  sMsgBoxText = sMsgBoxText + "MACAddress = " + nic["MACAddress"] + "\r\n";
>  sMsgBoxText = sMsgBoxText + "ServiceName = " + nic["ServiceName"] + "\r\n";
>				
>  if (nic["DefaultIPGateway"] != null)
>  {
>    sMsgBoxText = sMsgBoxText + "DefaultIPGateway = \r\n";
>    foreach (System.String sDefaultIPGateway in (System.String[]) nic["DefaultIPGateway"])
>    {
>	sMsgBoxText = sMsgBoxText + "      "+sDefaultIPGateway.ToString() + "\r\n";
>    }
>  }
>  else
>  {
>    sMsgBoxText = sMsgBoxText + "DefaultIPGateway = Returned NULL\r\n";
>  }
>
>  sMsgBoxText = sMsgBoxText + "IPSubnet = \r\n";
>  foreach (System.String sIPSubnet in (System.String[]) nic["IPSubnet"])
>  {
>    sMsgBoxText = sMsgBoxText + "      "+sIPSubnet.ToString() + "\r\n";
>  }
>
>
>  sMsgBoxText = sMsgBoxText + "IPAddress = \r\n";
>  foreach (System.String sIPAddress in (System.String[]) nic["IPAddress"])
>  {
>    sMsgBoxText = sMsgBoxText + "      "+sIPAddress.ToString() + "\r\n";
>  }
>
>
>
>  MessageBox.Show(sMsgBoxText,"Method #1");
>}
>
>
>Code is kind of sloppy but it is just some test code while I am learning more about WMI. Seems pretty powerfull.
>
>Now I just got to learn more about what gatway and subnet is all about. :)
>
>The reason I need to find the installed network adapters on a computer is so that the user can select which network to search for a device.
>Once the user has selected the network to search I have to broadcast a message to that network on a particular port and if there is a device of a particular type out there then that device will hopefully respond to me and from it's response I can find out the device's IP address so I can do further communication with the device.
>
>One of the things I need to learn more about is broadcasting.
>
>Einar

Nice work. FYI I ran the code on my system and it correctly identified 2 Network cards, 2 BlueTooth and the currently coonnected USB ADSL:)
PS: Also documenation suggests that one to get reliable info in win9x too.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform