Ejemplo n.º 1
0
        static bool Parse(string[] args)
        {
            for (int i = 0; i < args.Length - 1; i++)
            {
                switch (args[i])
                {
                case "-w":
                {
                    i++;
                    if (i >= args.Length - 1)
                    {
                        return(false);
                    }
                    if (!int.TryParse(args[i], out Timeout))
                    {
                        return(false);
                    }
                    if (Timeout <= 0)
                    {
                        return(false);
                    }
                }
                break;

                case "-i":
                {
                    i++;
                    if (i >= args.Length - 1)
                    {
                        return(false);
                    }
                    if (!int.TryParse(args[i], out MaxTtl))
                    {
                        return(false);
                    }
                    if (MaxTtl <= 0)
                    {
                        return(false);
                    }
                }
                break;

                case "-d":
                {
                    int            searcher;
                    IPSearcherImpl searcherImpl;

                    i++;
                    if (i >= args.Length - 1)
                    {
                        return(false);
                    }
                    if (!int.TryParse(args[i], out searcher))
                    {
                        return(false);
                    }
                    searcherImpl = (IPSearcherImpl)searcher;
                    Searcher     = IPSearcher.Create(searcherImpl);
                    if (Searcher == null)
                    {
                        return(false);
                    }
                }
                break;

                default:
                {
                    return(false);
                }
                }
            }

            if (args.Length == 0)
            {
                return(false);
            }
            if (!IPAddress.TryParse(args.Last(), out IP))
            {
                try
                {
                    IP = Dns.GetHostAddresses(args.Last())[0];
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }