Enumerating network adapters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to be able to enumerate network adapters and their configuration. Can somebody point out the appropriate object(s) in the dotnet framework for doing this? Thanks very much.
 
// Here's ur answer dude ...


using System ;
using System.Management ; // Ultra cool class that I think u should
investigate further :)
......


ManagementObjectSearcher q = new ManagementObjectSearcher("SELECT * FROM
Win32_NetworkAdapterConfiguration") ;
ManagementObjectCollection qc = q.Get() ;

foreach(ManagementObject mobj in qc)
{
Console.WriteLine( "'{0}'", mobj.ClassPath) ;
Console.WriteLine( "'{0}'", momobj.Options) ;
Console.WriteLine( "Index '{0}'", mobj("Index")) ;
Console.WriteLine( "MAC Address '{0}'", mobj("MacAddress")) ;
Console.WriteLine( "Description '{0}'", mobj("Description")) ;

if(mo("IPEnabled"))
{
String[] Addresses = (String[])mobj("IPAddress") ;
String[] Subnets = (String[])mobj("IPSubnet") ;
Console.WriteLine( "DNSHostName '{0}'", mobj("DNSHostName")) ;
Console.WriteLine( "DNSDomain '{0}'", mobj("DNSDomain")) ;

foreach(String s in Addresses)
Console.WriteLine( "IP Addy '{0}'", s) ;

foreach(String s in Subnets)
Console.WriteLine( "IP Subnet Mask '{0}'", s) ;
}
}

- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/



Russ Ferrill said:
I would like to be able to enumerate network adapters and their
configuration. Can somebody point out the appropriate object(s) in the
dotnet framework for doing this? Thanks very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top