How Can I Programtically Find All The Domains In My Local Network In Dot Net?

I need to list all the network domains(mshome, workgroup…) in my LAN . How can i get the list of all those domains programaticaslly in dot net?

One Comment

  1. Anu says:

    private void Page_Load(object sender, System.EventArgs e)
    {
    StringCollection adDomains = this.GetDomainList();
    foreach (string strDomain in adDomains)
    {
    Response.Write(“
    ” + strDomain + ““);
    }
    }
    private StringCollection GetDomainList()
    {
    StringCollection domainList = new StringCollection();
    try
    {
    DirectoryEntry en = new DirectoryEntry(“LDAP://”);
    // Search for objectCategory type “Domain”
    DirectorySearcher srch = new DirectorySearcher(“objectCategory=Domain…
    SearchResultCollection coll = srch.FindAll();
    // Enumerate over each returned domain.
    foreach (SearchResult rs in coll)
    {
    ResultPropertyCollection resultPropColl = rs.Properties;
    foreach( object domainName in resultPropColl["name"])
    {
    domainList.Add(domainName.ToString…
    }
    }
    }
    catch (Exception ex)
    {
    Trace.Write(ex.Message);
    }
    return domainList;
    }

Leave a Reply