I saw a question in a forum asking how to enumerate computers available in a domain. Though it might seem little difficult, it can be accomplished in less than 10 line of code. Thought would make it as a post for everyone’s benefit. Here we go:
public void PrintComputersInDomain (string domainName)
DirectoryEntry de = new DirectoryEntry ("LDAP://" + domainName);
foreach (DirectoryEntry c in de.Children)
Please note when you try this code, it might take seconds to finish if there are hundreds of computers in the given domain (of course, you can always do “kill process” J).
Yesterday, I came across a question in one of the .NET newsgroups asking how to get the IP address of the DNS servers available in the network. Though there is no direct way of getting this information (yet, at least to my knowledge) via .NET 2.0 class library, there is at least one indirect way:
For a change, the code snippet is in Visual Basic .NET :-)
Dim nics As NetworkInterface()
Dim dnsIPs As IPAddressCollection
nics = NetworkInterface.GetAllNetworkInterfaces()
For Each nic As NetworkInterface In nics
If (nic.OperationalStatus = OperationalStatus.Up) Then
dnsIPs = nic.GetIPProperties().DnsAddresses
For Each dnsIp As IPAddress In dnsIPs
Checking for operational status is not required unless you want to loop through inactive network interfaces as well.