Beispiel #1
0
        public List <String> GetDomainList()
        {
            int           entriesread = 0, totalentries = 0;
            List <String> NetworkList = new List <String>();

            try
            {
                do
                {
                    // Buffer to store the available servers
                    // Filled by the NetServerEnum function
                    IntPtr buf = new IntPtr();

                    NetServerAPIWrapper.SERVER_INFO_101 server;
                    int returnResult = NetServerAPIWrapper.NetServerEnum(null, 101, out buf, -1,
                                                                         ref entriesread, ref totalentries,
                                                                         NetServerAPIWrapper.SV_101_TYPES.SV_TYPE_DOMAIN_ENUM, null, IntPtr.Zero);

                    // if the function returned any data, fill the tree view
                    if (returnResult == NetServerAPIWrapper.ERROR_SUCCESS ||
                        returnResult == NetServerAPIWrapper.ERROR_MORE_DATA ||
                        entriesread > 0)
                    {
                        IntPtr ptr = buf;

                        for (int domainIndex = 0; domainIndex < entriesread; domainIndex++)
                        {
                            // cast pointer to a SERVER_INFO_101 structure
                            server = (NetServerAPIWrapper.SERVER_INFO_101)Marshal.PtrToStructure(ptr, typeof(NetServerAPIWrapper.SERVER_INFO_101));

                            //Cast the pointer to a ulong so this addition will work on 32-bit or 64-bit systems.
                            ptr = (IntPtr)((ulong)ptr + (ulong)Marshal.SizeOf(server));



                            NetworkList.Add(server.sv101_name);
                        }
                    }

                    // free the buffer
                    NetAPICommon.NetApiBufferFree(buf);
                }while
                (
                    entriesread < totalentries &&
                    entriesread != 0
                );
            }

            catch (Exception ex)
            {
                AMTLogger.WriteToLog(ex.Message, MethodBase.GetCurrentMethod().Name, 0, AMTLogger.LogInfo.Error);
            }

            return(NetworkList);
        }
Beispiel #2
0
        public List <DomainInfo> GetNetworkList()
        {
            int entriesread = 0, totalentries = 0;
            List <DomainInfo> NetworkList = new List <DomainInfo>();

            try
            {
                do
                {
                    // Buffer to store the available servers
                    // Filled by the NetServerEnum function
                    IntPtr buf = new IntPtr();

                    NetServerAPIWrapper.SERVER_INFO_101 server;
                    int returnResult = NetServerAPIWrapper.NetServerEnum(null, 101, out buf, -1,
                                                                         ref entriesread, ref totalentries,
                                                                         NetServerAPIWrapper.SV_101_TYPES.SV_TYPE_DOMAIN_ENUM, null, IntPtr.Zero);

                    // if the function returned any data, fill the tree view
                    if (returnResult == NetServerAPIWrapper.ERROR_SUCCESS ||
                        returnResult == NetServerAPIWrapper.ERROR_MORE_DATA ||
                        entriesread > 0)
                    {
                        IntPtr ptr = buf;

                        for (int domainIndex = 0; domainIndex < entriesread; domainIndex++)
                        {
                            // cast pointer to a SERVER_INFO_101 structure
                            server = (NetServerAPIWrapper.SERVER_INFO_101)Marshal.PtrToStructure(ptr, typeof(NetServerAPIWrapper.SERVER_INFO_101));

                            //Cast the pointer to a ulong so this addition will work on 32-bit or 64-bit systems.
                            ptr = (IntPtr)((ulong)ptr + (ulong)Marshal.SizeOf(server));



                            NetworkList.Add(new DomainInfo()
                            {
                                DomainName = server.sv101_name, Severs = GetServerList(server.sv101_name)
                            });
                        }
                    }

                    // free the buffer
                    NetAPICommon.NetApiBufferFree(buf);
                }while
                (
                    entriesread < totalentries &&
                    entriesread != 0
                );


                if (NetworkList.Count == 0)
                {
                    foreach (var testItem in new List <String>()
                    {
                        "D1", "D2", "D"
                    })
                    {
                        foreach (var serve in new List <String>()
                        {
                            "Dummy1", "Dummy2", "Dummy3", "Dummy4"
                        })
                        {
                            NetworkList.Add(new DomainInfo()
                            {
                                DomainName = testItem, Severs = new List <ServerInfo>()
                                {
                                    new ServerInfo {
                                        ServerName = serve, ServerType = 26, MajorVersion = 6, MinorVersion = 5, PlatformId = 6
                                    }
                                }
                            });
                        }
                    }

                    //NetworkList.Add(new DomainInfo() { DomainName = "localHost", Severs = new List<ServerInfo>() { new ServerInfo { ServerName = Environment.MachineName, ServerType = 26, MajorVersion = 6, MinorVersion = 5, PlatformId = 6 } } });
                }
            }

            catch (Exception ex)
            {
                AMTLogger.WriteToLog(ex.Message, MethodBase.GetCurrentMethod().Name, 0, AMTLogger.LogInfo.Error);
            }

            return(NetworkList);
        }
Beispiel #3
0
        public List <ServerInfo> GetServerList(String DomainName)
        {
            List <ServerInfo> serverItems = new List <ServerInfo>();
            int entriesread = 0, totalentries = 0;

            try
            {
                do
                {
                    // Buffer to store the available servers
                    // Filled by the NetServerEnum function
                    IntPtr buf = new IntPtr();
                    //NetServerAPIWrapper.SV_101_TYPES.SV_TYPE_WORKSTATION | NetServerAPIWrapper.SV_101_TYPES.SV_TYPE_SERVER
                    NetServerAPIWrapper.SERVER_INFO_101 server;
                    int returnResult = NetServerAPIWrapper.NetServerEnum(null, 101, out buf, -1,
                                                                         ref entriesread, ref totalentries,

                                                                         NetServerAPIWrapper.SV_101_TYPES.SV_TYPE_WORKSTATION |
                                                                         NetServerAPIWrapper.SV_101_TYPES.SV_TYPE_DOMAIN_CTRL | NetServerAPIWrapper.SV_101_TYPES.SV_TYPE_DOMAIN_BAKCTRL


                                                                         , DomainName, IntPtr.Zero);

                    // if the function returned any data, fill the tree view
                    if (returnResult == NetServerAPIWrapper.ERROR_SUCCESS ||
                        returnResult == NetServerAPIWrapper.ERROR_MORE_DATA ||
                        entriesread > 0)
                    {
                        IntPtr ptr = buf;

                        for (int domainIndex = 0; domainIndex < entriesread; domainIndex++)
                        {
                            // cast pointer to a SERVER_INFO_101 structure
                            server = (NetServerAPIWrapper.SERVER_INFO_101)Marshal.PtrToStructure(ptr, typeof(NetServerAPIWrapper.SERVER_INFO_101));

                            //Cast the pointer to a ulong so this addition will work on 32-bit or 64-bit systems.
                            ptr = (IntPtr)((ulong)ptr + (ulong)Marshal.SizeOf(server));



                            serverItems.Add(new ServerInfo()
                            {
                                ServerName   = server.sv101_name,
                                PlatformId   = server.sv101_platform_id,
                                ServerType   = server.sv101_type,
                                MinorVersion = server.sv101_version_minor,
                                MajorVersion = server.sv101_version_major,
                                Comment      = server.sv101_comment
                            }


                                            );
                        }
                    }

                    // free the buffer
                    NetAPICommon.NetApiBufferFree(buf);
                }while
                (
                    entriesread < totalentries &&
                    entriesread != 0
                );



                if (serverItems.Count == 0)
                {
                    foreach (var testItem in new List <String>()
                    {
                        "Dummy1", "Dummy2", "Dummy3", "Dummy4"
                    })
                    {
                        serverItems.Add(new ServerInfo()
                        {
                            ServerName = DomainName + testItem
                        });
                    }
                }
            }



            catch (Exception ex)
            {
                AMTLogger.WriteToLog(ex.Message, MethodBase.GetCurrentMethod().Name, 0, AMTLogger.LogInfo.Error);
            }

            return(serverItems);
        }