Esempio n. 1
0
        private static Win32Error ParseArguments(string[] args, out string QueryName, out DNS_TYPE QueryType, out DNS_QUERY_OPTIONS QueryOptions, out string ServerIp)
        {
            int        CurrentIndex         = 0;
            bool       ArgContainsQueryName = false;
            Win32Error Error = Win32Error.ERROR_INVALID_PARAMETER;

            QueryType    = DNS_TYPE.DNS_TYPE_A; // default type
            QueryOptions = 0;                   // default query options
            QueryName    = string.Empty;
            ServerIp     = string.Empty;

            while (CurrentIndex < args.Length)
            {
                // Query Name:

                if (StringComparer.OrdinalIgnoreCase.Compare(args[CurrentIndex], "-q") == 0)
                {
                    CurrentIndex++;
                    if (CurrentIndex < args.Length)
                    {
                        QueryName            = args[CurrentIndex];
                        ArgContainsQueryName = true;
                    }
                    else
                    {
                        goto exit;
                    }
                }

                // Query Type
                else if (StringComparer.OrdinalIgnoreCase.Compare(args[CurrentIndex], "-t") == 0)
                {
                    CurrentIndex++;
                    if (CurrentIndex < args.Length)
                    {
                        QueryType = ExtractUserFriendlyQueryType(args[CurrentIndex]);
                        if (QueryType == 0)
                        {
                            goto exit;
                        }
                    }
                    else
                    {
                        goto exit;
                    }
                }

                // Query Options
                else if (StringComparer.OrdinalIgnoreCase.Compare(args[CurrentIndex], "-o") == 0)
                {
                    CurrentIndex++;
                    if (CurrentIndex < args.Length)
                    {
                        try { QueryOptions = ExtractUserFriendlyQueryOptions(args[CurrentIndex]); }
                        catch { goto exit; }
                    }
                    else
                    {
                        goto exit;
                    }
                }

                // Server List
                else if (StringComparer.OrdinalIgnoreCase.Compare(args[CurrentIndex], "-s") == 0)
                {
                    CurrentIndex++;
                    if (CurrentIndex < args.Length)
                    {
                        ServerIp = args[CurrentIndex];
                    }
                    else
                    {
                        goto exit;
                    }
                }
                else
                {
                    goto exit;
                }
                CurrentIndex++;
            }

            if (ArgContainsQueryName)
            {
                Error = Win32Error.ERROR_SUCCESS;
            }

exit:
            if (Error.Failed)
            {
                PrintHelp();
            }

            return(Error);
        }
Esempio n. 2
0
 internal static extern int DnsQuery_W([MarshalAs(UnmanagedType.LPWStr)] string pszName, DNS_TYPE wType, QueryOptions Options, IP4_ARRAY aipServers, ref IntPtr ppQueryResults, IntPtr pReserved);
Esempio n. 3
0
 private static extern int DnsQuery_W(string pszName, DNS_TYPE wType, DNS_QUERY options, IntPtr pExtra, out IntPtr ppQueryResults, IntPtr pReserved);