コード例 #1
0
        private static CommandResult PerformPing(string ip, string computerName, int count, int timeout, int ttl)
        {
            CommandResult results = new CommandResult(count);

            Ping        ping    = new Ping();
            PingOptions options = new PingOptions(ttl, false);

            bool succeeded = false;

            for (int i = 0; i < count; i++)
            {
                PingReply reply = null;

                try
                {
                    reply = ping.Send(ip, timeout, alphabet, options);
                }
                catch (PingException)
                {
                    break;
                }

                succeeded = true;

                // Add to output
                results.Add(
                    new ResultRecord()
                {
                    { "ComputerName", computerName },
                    { "RemoteAddress", (reply.Address != null) ? reply.Address.ToString() : null },
                    { "PingSucceeded", reply.Status == IPStatus.Success ? "True" : "False" },
                    { "PingReplyDetails (RTT)", reply.RoundtripTime.ToString() }
                }
                    );

                // Send only 1 request per second
                //if (i != count - 1)
                //    Thread.Sleep(1000 - (int)reply.RoundtripTime);
            }

            // Error response
            if (!succeeded)
            {
                results.Add(new ResultRecord()
                {
                    { "ComputerName", computerName },
                    { "RemoteAddress", string.Empty },
                    { "PingSucceeded", succeeded ? "True" : "False" }
                });
            }

            return(results);
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: Nestor/IW4M-Admin
        /// <summary>
        /// Send a message to a particular players
        /// </summary>
        /// <param name="Message">Message to send</param>
        /// <param name="Target">Player to send message to</param>
        public async Task Tell(String Message, Player Target)
        {
            string tellCommand = (GameName == Game.IW4) ? "tellraw" : "tell";

#if !DEBUG
            if (Target.ClientNumber > -1 && Message.Length > 0 && Target.Level != Player.Permission.Console)
            {
                await this.ExecuteCommandAsync($"{tellCommand} {Target.ClientNumber} {Message}^7");
            }
#else
            Logger.WriteVerbose($"{Target.ClientNumber}->{Message.StripColors()}");
#endif

            if (Target.Level == Player.Permission.Console)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(Utilities.StripColors(Message));
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            if (CommandResult.Count > 15)
            {
                CommandResult.RemoveAt(0);
            }
            CommandResult.Add(new CommandResponseInfo()
            {
                Response = Utilities.StripColors(Message),
                ClientId = Target.ClientId
            });
        }
コード例 #3
0
        private static CommandResult PerformPortTest(string ip, string computerName, int port)
        {
            CommandResult results = new CommandResult(1);

            if (port < 1 || port > 65535)
            {
                throw new NoPowerShellException("Cannot validate argument on parameter 'Port'. The {0} argument is greater than the maximum allowed range of 65535. Supply an argument that is less than or equal to 65535 and then try the command again.", port);
            }

            bool connected = false;

            try
            {
                TcpClient client       = new TcpClient(ip, port);
                string    address      = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
                string    localAddress = ((IPEndPoint)client.Client.LocalEndPoint).Address.ToString();
                connected = true;

                results.Add(new ResultRecord()
                {
                    { "ComputerName", computerName },
                    { "RemoteAddress", address },
                    { "RemotePort", port.ToString() },
                    //{ "InterfaceAlias", string.Empty }, // TODO
                    { "SourceAddress", localAddress },
                    { "TcpTestSucceeded", connected ? "True" : "False" }
                });
            }
            catch (SocketException)
            {
                throw new NoPowerShellException("TCP connect to ({0} : {1}) failed", ip, port);
            }

            return(results);
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: Balalayker/IW4M-Admin
        /// <summary>
        /// Send a message to a particular players
        /// </summary>
        /// <param name="Message">Message to send</param>
        /// <param name="Target">Player to send message to</param>
        public async Task Tell(String Message, Player Target)
        {
#if !DEBUG
            string formattedMessage = String.Format(RconParser.GetCommandPrefixes().Tell, Target.ClientNumber, Message);
            if (Target.ClientNumber > -1 && Message.Length > 0 && Target.Level != Player.Permission.Console)
            {
                await this.ExecuteCommandAsync(formattedMessage);
            }
#else
            Logger.WriteVerbose($"{Target.ClientNumber}->{Message.StripColors()}");
            await Utilities.CompletedTask;
#endif

            if (Target.Level == Player.Permission.Console)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(Utilities.StripColors(Message));
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            if (CommandResult.Count > 15)
            {
                CommandResult.RemoveAt(0);
            }

            CommandResult.Add(new CommandResponseInfo()
            {
                Response = Utilities.StripColors(Message),
                ClientId = Target.ClientId
            });
        }
コード例 #5
0
        private CommandResult BrowseEnvironment(string path)
        {
            CommandResult results = new CommandResult();

            string[] selection = path.Split(':');
            string   filter    = null;

            if (selection.Length > 1)
            {
                filter = selection[1];
            }

            Hashtable variables = new Hashtable((Hashtable)Environment.GetEnvironmentVariables(), StringComparer.InvariantCultureIgnoreCase);

            // Obtain specific variable
            if (!string.IsNullOrEmpty(filter))
            {
                if (!variables.ContainsKey(filter))
                {
                    throw new Exception(string.Format("Cannot find path '{0}' because it does not exist.", filter));
                }

                results.Add(
                    new ResultRecord()
                {
                    { "Name", filter },
                    { "Value", variables[filter].ToString() }
                }
                    );
            }
            // Obtain all variables
            else
            {
                foreach (DictionaryEntry variable in variables)
                {
                    results.Add(
                        new ResultRecord()
                    {
                        { "Name", variable.Key.ToString() },
                        { "Value", variable.Value.ToString() }
                    }
                        );
                }
            }

            return(results);
        }
コード例 #6
0
ファイル: ValidationFacade.cs プロジェクト: rtennys/Momo
        public CommandResult Validate(object instance)
        {
            var validationResults = new List<ValidationResult>();
            Validator.TryValidateObject(instance, new ValidationContext(instance), validationResults, true);

            var serviceResult = new CommandResult();

            foreach (var validationResult in validationResults)
                serviceResult.Add(validationResult.MemberNames.Join(", "), validationResult.ErrorMessage);

            return serviceResult;
        }
コード例 #7
0
        private static CommandResult BrowseRegistry(RegistryKey root, string path, bool includeHidden)
        {
            CommandResult results = new CommandResult();

            RegistryKey key = root.OpenSubKey(path);

            foreach (string subkey in key.GetSubKeyNames())
            {
                results.Add(
                    new ResultRecord()
                {
                    { "Name", subkey }
                }
                    );
            }

            return(results);
        }
コード例 #8
0
ファイル: Server.cs プロジェクト: mldYM/IW4M-Admin
        /// <summary>
        /// Send a message to a particular players
        /// </summary>
        /// <param name="Message">Message to send</param>
        /// <param name="Target">EFClient to send message to</param>
        protected async Task Tell(String Message, EFClient Target)
        {
#if !DEBUG
            string formattedMessage = String.Format(RconParser.Configuration.CommandPrefixes.Tell, Target.ClientNumber, $"{(CustomSayEnabled ? $"{CustomSayName}: " : "")}{Message}");
            if (Target.ClientNumber > -1 && Message.Length > 0 && Target.Level != EFClient.Permission.Console)
            {
                await this.ExecuteCommandAsync(formattedMessage);
            }
#else
            Logger.WriteVerbose($"{Target.ClientNumber}->{Message.StripColors()}");
            await Task.CompletedTask;
#endif

            if (Target.Level == EFClient.Permission.Console)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(Message.StripColors());
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            // prevent this from queueing up too many command responses
            if (CommandResult.Count > 15)
            {
                CommandResult.RemoveAt(0);
            }

            // it was a remote command so we need to add it to the command result queue
            if (Target.ClientNumber < 0)
            {
                CommandResult.Add(new CommandResponseInfo()
                {
                    Response = Message.StripColors(),
                    ClientId = Target.ClientId
                });
            }
        }
コード例 #9
0
        /// <summary>
        /// Query host based on type
        /// </summary>
        /// <param name="domain">Domain to query</param>
        /// <param name="type">Query type</param>
        /// <returns>List of records</returns>
        public static CommandResult GetRecords(string domain, string type)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new NotSupportedException();
            }

            CommandResult results   = new CommandResult();
            object        foundType = RecordTypes[type];

            if (foundType == null)
            {
                string[] types = new string[RecordTypes.Count];
                RecordTypes.Keys.CopyTo(types, 0);
                throw new NoPowerShellException("Invalid type specified. Specify one of the following: {0}.", string.Join(",", types));
            }
            DnsRecordTypes queryType = (DnsRecordTypes)foundType;

            var recordsArray = IntPtr.Zero;

            try
            {
                var result = DnsQuery(ref domain, queryType, DnsQueryOptions.DNS_QUERY_BYPASS_CACHE, IntPtr.Zero, ref recordsArray, IntPtr.Zero);
                if (result != 0)
                {
                    throw new Win32Exception(result);
                }

                DNS_RECORD record;
                for (var recordPtr = recordsArray; !recordPtr.Equals(IntPtr.Zero); recordPtr = record.pNext)
                {
                    record = (DNS_RECORD)Marshal.PtrToStructure(recordPtr, typeof(DNS_RECORD));
                    switch (record.wType)
                    {
                    case (ushort)DnsRecordTypes.DNS_TYPE_A:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "A" },
                            { "IPAddress", ConvertUintToIpAddressString(record.Data.A.IpAddress) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_NS:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "NS" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.NS.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MD:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MD" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MD.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MF:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MF" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MF.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_CNAME:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "CNAME" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.CNAME.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_SOA:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "SOA" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.SOA.pNamePrimaryServer) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MB:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MB" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MB.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MG:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MG" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MG.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MR:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MR" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MR.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_WKS:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "WKS" },
                            { "Protocol", ((int)record.Data.WKS.chProtocol).ToString() },
                            { "Mask", ((int)record.Data.WKS.BitMask).ToString() },
                            { "IPAddress", ConvertUintToIpAddressString(record.Data.WKS.IpAddress) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_PTR:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "PTR" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.PTR.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MX:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MX" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MX.pNameExchange) },
                            { "Preference", record.Data.MX.wPreference.ToString() }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_TEXT:
                        for (uint i = 0; i < record.Data.TXT.dwStringCount; i++)
                        {
                            results.Add(
                                new ResultRecord()
                            {
                                { "Name", Marshal.PtrToStringAuto(record.pName) },
                                { "Type", "TXT" },
                                { "Strings", Marshal.PtrToStringAuto(record.Data.TXT.pStringArray) },
                            }
                                );
                        }
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_RT:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "RT" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.RT.pNameExchange) },
                            { "Preference", record.Data.RT.wPreference.ToString() }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_AAAA:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "AAAA" },
                            { "IPAddress", ConvertAAAAToIpAddress(record.Data.AAAA).ToString() }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_SRV:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "SRV" },
                            { "PrimaryServer", Marshal.PtrToStringAuto(record.Data.SRV.pNameTarget) },
                        }
                            );
                        break;

                    default:
                        throw new Exception(string.Format("Unknown: %s type %d", record.pName, record.wType));
                    }
                }

                return(results);
            }
            finally
            {
                if (recordsArray != IntPtr.Zero)
                {
                    DnsRecordListFree(recordsArray, DNS_FREE_TYPE.DnsFreeFlat);
                }
            }
        }
コード例 #10
0
        public static CommandResult BrowseFilesystem(string path, bool recurse, int depth, bool includeHidden, string searchPattern)
        {
            CommandResult results = new CommandResult();

            DirectoryInfo gciDir = new DirectoryInfo(path);

            if (!gciDir.Exists)
            {
                throw new ItemNotFoundException(path);
            }

            // TODO: Follow symlinks. Skipping them for now
            if ((gciDir.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
            {
                return(results);
            }

            DirectoryInfo[] directories;
            try
            {
                directories = gciDir.GetDirectories(recurse ? "*" : searchPattern);
            }
            catch (UnauthorizedAccessException)
            {
                Console.WriteLine("Unauthorized to access \"{0}\"", path);
                return(results);
            }

            FileInfo[] files = gciDir.GetFiles(searchPattern);

            // Enumerate directories
            foreach (DirectoryInfo dir in directories)
            {
                if (!includeHidden && ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
                {
                    continue;
                }

                // Don't show directories if -Recurse and an -Include filter is set
                if (recurse && !string.IsNullOrEmpty(searchPattern))
                {
                    continue;
                }

                ResultRecord currentDir = new ResultRecord()
                {
                    { "Mode", GetModeFlags(dir) },
                    { "LastWriteTime", dir.LastWriteTime.ToString() },
                    { "Length", string.Empty },
                    { "Name", dir.Name }
                };

                // If recursive, also the directory name is needed
                if (recurse)
                {
                    currentDir.Add("Directory", dir.FullName);
                }

                results.Add(currentDir);
            }

            // Enumerate files
            foreach (FileInfo file in files)
            {
                if (!includeHidden && ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
                {
                    continue;
                }

                ResultRecord currentFile = new ResultRecord()
                {
                    { "Mode", GetModeFlags(file) },
                    { "LastWriteTime", file.LastWriteTime.ToString() },
                    { "Length", file.Length.ToString() },
                    { "Name", file.Name }
                };

                // If recursive, also the directory name is needed
                if (recurse)
                {
                    currentFile.Add("Directory", file.Directory.FullName);
                }

                results.Add(currentFile);
            }

            // After adding folders and files in current directory, go depth first
            if (recurse && depth > 0)
            {
                foreach (DirectoryInfo subDir in directories)
                {
                    // Skip hidden directories in case -Force parameter is not provided
                    if ((subDir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden && !includeHidden)
                    {
                        continue;
                    }

                    CommandResult currentDir = BrowseFilesystem(subDir.FullName, recurse, depth - 1, includeHidden, searchPattern);
                    results.AddRange(currentDir);
                }
            }

            return(results);
        }
コード例 #11
0
        private static CommandResult PerformTraceroute(string ip, string computerName, int count, int timeout, int maxHops)
        {
            CommandResult results = new CommandResult(count);

            Ping          ping = new Ping();
            List <string> IPs  = new List <string>(maxHops);

            // Last hop details
            string remoteAddress = string.Empty;
            bool   succeeded     = false;
            int    rtt           = -1;

            for (int ttl = 1; ttl <= maxHops; ttl++)
            {
                PingOptions options = new PingOptions(ttl, true);
                PingReply   reply   = null;

                try
                {
                    reply = ping.Send(ip, timeout, alphabet, options);
                }
                catch (PingException)
                {
                    break;
                }

                if (reply.Status == IPStatus.TtlExpired)
                {
                    IPs.Add(reply.Address.ToString());
                }
                else if (reply.Status == IPStatus.TimedOut)
                {
                    IPs.Add("*");
                }
                else if (reply.Status == IPStatus.Success)
                {
                    IPs.Add(reply.Address.ToString());
                    remoteAddress = reply.Address.ToString();
                    succeeded     = true;
                    rtt           = (int)reply.RoundtripTime;
                    break;
                }
            }

            ResultRecord record = new ResultRecord()
            {
                { "ComputerName", computerName },
                { "RemoteAddress", remoteAddress },
                { "PingSucceeded", succeeded ? "True" : "False" }
            };

            if (succeeded)
            {
                record.Add("PingReplyDetails (RTT)", rtt.ToString());
                record.Add("TraceRoute", string.Join(", ", IPs.ToArray()));
            }

            results.Add(record);

            return(results);
        }
コード例 #12
0
        /// <summary>
        /// Query host based on type
        /// </summary>
        /// <param name="domain">Domain to query</param>
        /// <param name="type">Query type</param>
        /// <returns>List of records</returns>
        public static CommandResult GetRecords(string domain, string type)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new NotSupportedException();
            }

            CommandResult  results   = new CommandResult();
            DnsRecordTypes queryType = (DnsRecordTypes)recordTypes[type];

            var recordsArray = IntPtr.Zero;

            try
            {
                var result = DnsQuery(ref domain, queryType, DnsQueryOptions.DNS_QUERY_BYPASS_CACHE, IntPtr.Zero, ref recordsArray, IntPtr.Zero);
                if (result != 0)
                {
                    throw new Win32Exception(result);
                }

                DNS_RECORD record;
                var        recordList = new List <string>();
                for (var recordPtr = recordsArray; !recordPtr.Equals(IntPtr.Zero); recordPtr = record.pNext)
                {
                    record = (DNS_RECORD)Marshal.PtrToStructure(recordPtr, typeof(DNS_RECORD));
                    switch (record.wType)
                    {
                    case (ushort)DnsRecordTypes.DNS_TYPE_A:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "A" },
                            { "IPAddress", ConvertUintToIpAddressString(record.Data.A.IpAddress) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_NS:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "NS" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.NS.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MD:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MD" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MD.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MF:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MF" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MF.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_CNAME:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "CNAME" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.CNAME.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_SOA:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "SOA" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.SOA.pNamePrimaryServer) }
                        }
                            );
                        break;

                    //message.Format("   SOA %s  nameserv: %s\r\n", record->pName, record.Data.SOA.pNamePrimaryServer);

                    //temp.Format("              admin: %s\r\n", record.Data.SOA.pNameAdministrator);
                    //message += temp;
                    //temp.Format("             serial: %u\r\n", record.Data.SOA.dwSerialNo);
                    //message += temp;
                    //temp.Format("            refresh: %u\r\n", record.Data.SOA.dwRefresh);
                    //message += temp;
                    //temp.Format("                ttl: %u\r\n", record.Data.SOA.dwDefaultTtl);
                    //message += temp;
                    //temp.Format("             expire: %u\r\n", record.Data.SOA.dwExpire);
                    //message += temp;
                    //temp.Format("              retry: %u", record.Data.SOA.dwRetry);
                    //message += temp;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MB:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MB" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MB.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MG:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MG" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MG.pNameHost) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MR:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MR" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MR.pNameHost) }
                        }
                            );
                        break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_NULL:
                    //  message.Format("   MB %s %s",record->pName,record.Data.Null.MR.pNameHost);
                    //break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_WKS:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "WKS" },
                            { "Protocol", ((int)record.Data.WKS.chProtocol).ToString() },
                            { "Mask", ((int)record.Data.WKS.BitMask).ToString() },
                            { "IPAddress", ConvertUintToIpAddressString(record.Data.WKS.IpAddress) }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_PTR:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "PTR" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.PTR.pNameHost) }
                        }
                            );
                        break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_HINFO:
                    //    message.Format("   HINFO %s", record->pName);
                    //    for (u_int i = 0; i < record.Data.HINFO.dwStringCount; i++)
                    //    {
                    //        message += "\r\n            ";
                    //        message += record.Data.HINFO.pStringArray[i];
                    //    }
                    //    break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_MINFO:
                    //    message.Format("   MINFO %s err: %s name: %s", record->pName, record.Data.MINFO.pNameErrorsMailbox, record.Data.MINFO.pNameMailbox);
                    //    break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_MX:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "MX" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.MX.pNameExchange) },
                            { "Preference", record.Data.MX.wPreference.ToString() }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_TEXT:
                        for (uint i = 0; i < record.Data.TXT.dwStringCount; i++)
                        {
                            results.Add(
                                new ResultRecord()
                            {
                                { "Name", Marshal.PtrToStringAuto(record.pName) },
                                { "Type", "TXT" },
                                { "Strings", Marshal.PtrToStringAuto(record.Data.TXT.pStringArray) },
                            }
                                );
                        }
                        break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_RP:
                    //    message.Format("   RP %s err: %s name: %s", record->pName, record.Data.RP.pNameErrorsMailbox, record.Data.RP.pNameMailbox);
                    //    break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_AFSDB:
                    //    message.Format("   AFSDB %s %s pref: %d", record->pName, record.Data.AFSDB.pNameExchange, record.Data.AFSDB.wPreference);
                    //    break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_X25:
                    //    message.Format("   X25 %s", record->pName);
                    //    for (u_int i = 0; i < record.Data.X25.dwStringCount; i++)
                    //    {
                    //        message += "\r\n            ";
                    //        message += record.Data.X25.pStringArray[i];
                    //    }
                    //    break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_ISDN:
                    //    message.Format("   ISDN %s", record->pName);
                    //    for (u_int i = 0; i < record.Data.ISDN.dwStringCount; i++)
                    //    {
                    //        message += "\r\n            ";
                    //        message += record.Data.ISDN.pStringArray[i];
                    //    }
                    //    break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_RT:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "RT" },
                            { "NameHost", Marshal.PtrToStringAuto(record.Data.RT.pNameExchange) },
                            { "Preference", record.Data.RT.wPreference.ToString() }
                        }
                            );
                        break;


                    //case (ushort)DnsRecordTypes.DNS_TYPE_SIG:
                    //break;
                    //case (ushort)DnsRecordTypes.DNS_TYPE_KEY:
                    //break;


                    case (ushort)DnsRecordTypes.DNS_TYPE_AAAA:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "AAAA" },
                            { "IPAddress", ConvertAAAAToIpAddress(record.Data.AAAA).ToString() }
                        }
                            );
                        break;

                    case (ushort)DnsRecordTypes.DNS_TYPE_SRV:
                        results.Add(
                            new ResultRecord()
                        {
                            { "Name", Marshal.PtrToStringAuto(record.pName) },
                            { "Type", "SRV" },
                            { "PrimaryServer", Marshal.PtrToStringAuto(record.Data.SRV.pNameTarget) },
                        }
                            );
                        break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_WINS:
                    //break;

                    //case (ushort)DnsRecordTypes.DNS_TYPE_WINSR:
                    //    message.Format("   NBSTAT %s %s", record->pName, record.Data.WINSR.pNameResultDomain);
                    //    break;

                    default:
                        throw new Exception(string.Format("Unknown: %s type %d", record.pName, record.wType));
                    }

                    //if (record->Flags.S.Section == DNSREC_AUTHORITY)
                    //    message += "   (authority)";
                    //if (record->Flags.S.Section == DNSREC_ADDITIONAL)
                    //    message += "   (additional)";

                    //pEdit->SetSel(pEdit->GetWindowTextLength(), pEdit->GetWindowTextLength());
                    //pEdit->ReplaceSel(message + "\r\n");


                    //Console.WriteLine(Marshal.PtrToStringAnsi(record.pName));
                    if (record.wType == (int)DnsRecordTypes.DNS_TYPE_MX)
                    {
                        recordList.Add(Marshal.PtrToStringAuto(record.Data.MX.pNameExchange));
                    }
                }

                return(results);
            }
            finally
            {
                if (recordsArray != IntPtr.Zero)
                {
                    DnsRecordListFree(recordsArray, DNS_FREE_TYPE.DnsFreeFlat);
                }
            }
        }