让网络上的所有域名域名、网络

2023-09-08 13:14:56 作者:人傻不能怪社会°

我需要让我的网络上的域名列表...

但我只得到与我登录到域的名称... 因此,例如有2个域XYZ和XYZ2 但我只得到与我登录到域中......

这是我的code:

 如果(!的IsPostBack)
        {

            StringCollection adDomains = this.GetDomainList();

                的foreach(在adDomains串strDomain)
                {
                    DropDownList1.Items.Add(strDomain);

                }
            }
        }

    私人StringCollection GetDomainList()
    {
        StringCollection的domainlist =新StringCollection();
        尝试
        {
            的DirectoryEntry EN =新的DirectoryEntry(LDAP://);
            //搜索objectCategory属性类型域
            DirectorySearcher从SRCH =新DirectorySearcher从(objectCategory属性=域);
            SearchResultCollection科尔= srch.FindAll();
            //枚举每个返回的域名。
            的foreach(在科尔信息搜索结果RS)
            {
                ResultPropertyCollection resultPropColl = rs.Properties;
                的foreach(对象则domainName在resultPropColl [名称])
                {
                    domainList.Add(domainName.ToString());
                }
            }
        }
        赶上(例外前)
        {
            Trace.Write(ex.Message);
        }
        返回的domainlist;
    }
 

解决方案

 使用System.DirectoryServices.ActiveDirectory;
 

...

 森林currentForest = Forest.GetCurrentForest();
DomainCollection域= currentForest.Domains;
的foreach(域objDomain会在域)
{
   System.Diagnostics.Debug.WriteLine(objDomain.Name);
}
 
10分钟23张图,带你了解中国互联网现状

i need to get the list of domain names on my network...

but i am only getting the domain name with which i log into... so for example there are 2 domains "xyz" and "xyz2" but i get only the domain with which i log into....

here is my code:

if (!IsPostBack)
        {

            StringCollection adDomains = this.GetDomainList();

                foreach (string strDomain in adDomains)
                {
                    DropDownList1.Items.Add(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;
    }               

解决方案

using System.DirectoryServices.ActiveDirectory;  

....

Forest currentForest = Forest.GetCurrentForest();  
DomainCollection domains = currentForest.Domains;  
foreach(Domain objDomain in domains)  
{  
   System.Diagnostics.Debug.WriteLine(objDomain.Name);  
}