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.
 
Back
Top