DirectoryEntry parent = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry dm in parent.Children)
{
    if (dm.SchemaClassName == "Domain")
        Console.WriteLine("Domain {0}", dm.Name);
    else
        continue;

    // Scan Computers on this domain
    DirectoryEntry coParent = new DirectoryEntry("WinNT://" + dm.Name);
    foreach (DirectoryEntry client in coParent.Children)
    {
        if (client.SchemaClassName == "Computer")
            Console.WriteLine("    Computer {0}", client.Name);
        else
            continue;
        // The computer may be in the directory, but not online
        try
        {
            System.Net.IPHostEntry addr = Dns.GetHostEntry(client.Name);
            if (addr != null && addr.AddressList.Length > 0)
            {
                for (int i = 0; i < addr.AddressList.Length; i++)
                    Console.WriteLine("        IP Address: {0}", 
                        addr.AddressList[i].ToString());
            }
        }
        catch (Exception) { }
    }
}