예제 #1
0
        //
        //    Add
        //    ===
        //
        //    Adds a 'new' entry to the list of discovered assets.
        //
        public bool Add(DiscoveredItem newitem)
        {
            if (newitem.IPAddress.Length == 0)
            {
                newitem.IPAddress = IpAddress(newitem.Name);
            }

            // ..and log the progress
            ProgressDetails progressDetails = new ProgressDetails(ProgressDetails.eState.success, newitem.ToString());

            progressDetails.Tag = newitem;
            bool bCancelled = !TryShowProgress(progressDetails);

            return(bCancelled);
        }
예제 #2
0
        // Constructor - takes the LDAP Server name asan input

        //
        //    Discover
        //    ========
        //
        //    Base class over-ride to perform the actual work
        //
        public override int Discover()
        {
            try
            {
                // Identify the 'default' AD/LDAP Server
                DirectoryEntry defaultServer = new DirectoryEntry("LDAP://rootDSE");
                string         strLdapServer = (string)defaultServer.Properties["defaultNamingContext"].Value;
                DirectoryEntry mySearchRoot  = new DirectoryEntry("LDAP://" + strLdapServer);

                // Create a 'DirectoryEntry' object to search.
                DirectorySearcher myDirectorySearcher = new DirectorySearcher(mySearchRoot);
                myDirectorySearcher.Filter = ("(objectClass=computer)");

                // Iterate through (any) results
                foreach (SearchResult resEnt in myDirectorySearcher.FindAll())
                {
                    // Get the 'DirectoryEntry' that corresponds to 'mySearchResult'.
                    DirectoryEntry myDirectoryEntry = resEnt.GetDirectoryEntry();
                    string         strComputer      = myDirectoryEntry.Name.ToString();

                    // strip off the 'CN=' if it exists
                    if (strComputer.StartsWith("CN="))
                    {
                        strComputer = strComputer.Remove(0, 3);
                    }

                    // What OU is this computer in though?
                    string strParent = myDirectoryEntry.Path;
                    strParent = GetOU(strParent);

                    // ...and add this to our list
                    string         thisIp     = IpAddress(strComputer);
                    DiscoveredItem item       = new DiscoveredItem(strComputer, strParent, thisIp);
                    bool           bCancelled = Add(item);
                    if (bCancelled)
                    {
                        break;
                    }
                }
            }
            catch (Exception)
            {
                TryShowProgress(new ProgressDetails(ProgressDetails.eState.failure, "Failed to locate/connect to the Active Directory Server"));
                return(-1);                                                             // Server probably doesn't exist
            }

            return(0);
        }
예제 #3
0
        // Constructor

        //
        //    Discover
        //    ========
        //
        //    Base class over-ride to perform the actual work
        //
        public override int Discover()
        {
            try
            {
                ServerEnum servers = new ServerEnum(ResourceScope.RESOURCE_GLOBALNET
                                                    , ResourceType.RESOURCETYPE_DISK
                                                    , ResourceUsage.RESOURCEUSAGE_ALL
                                                    , ResourceDisplayType.RESOURCEDISPLAYTYPE_SERVER);

                // The data is returned in an array list with the name encapsulated in the form
                // domain\\PC which we have to split and add to our own list
                foreach (Server server in servers)
                {
                    string strComputer = server.Name.ToString();
                    string strDomain   = server.Domain.ToString();

                    // Skip any where we have no domain
                    if (strDomain == "")
                    {
                        continue;
                    }

                    // ...and add this to our list
                    string         thisIp     = IpAddress(strComputer);
                    DiscoveredItem item       = new DiscoveredItem(strComputer, strDomain, thisIp);
                    bool           bCancelled = Add(item);
                    if (bCancelled)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                return(-1);                                                             // Server probably doesn't exist
            }

            return(0);
        }