Beispiel #1
0
        static int Main(string[] args)
        {
            Opts opts;

            if (!Opts.TryParse(args, out opts))
            {
                return(1);
            }
            try
            {
                TextReader hostnames;
                if (String.IsNullOrEmpty(opts.filename))
                {
                    hostnames = Console.In;
                }
                else
                {
                    hostnames = new StreamReader(opts.filename, detectEncodingFromByteOrderMarks: true);
                }
                using (hostnames)
                {
                    new MaxTasks().Start(
                        tasks: Spi.Misc.ReadLines(hostnames).Select(h => ResolveAndPingAsync(h.Trim(), opts.resolveOnly)),
                        MaxParallel: 128)
                    .Wait();
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                return(8);
            }
            return(0);
        }
Beispiel #2
0
        public static bool TryParse(string[] args, out Opts opts)
        {
            bool showHelp = false;

            opts = null;
            Opts tmpOpts = new Opts()
            {
                resolveOnly = false,
                filename    = null
            };

            var options = new Spi.BeeOptsBuilder()
                          .Add('h', "help", Spi.OPTTYPE.BOOL, "print usage", v => showHelp = true)
                          .Add('r', "resolve", Spi.OPTTYPE.BOOL, "only resolve hostnames", v => tmpOpts.resolveOnly = true)
                          .GetOpts();

            List <string> argValues = Spi.BeeOpts.Parse(args, options, OnUnknown: null);

            if (argValues.Count > 0)
            {
                tmpOpts.filename = argValues[0];
            }

            if (showHelp)
            {
                ShowUsage(options);
                return(false);
            }

            opts = tmpOpts;
            return(true);
        }