Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What network cards are installed on my computer?
Message
 
À
24/11/2004 11:06:27
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00963864
Message ID:
00964381
Vues:
9
>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
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform