Пример #1
0
        public static void Main(string[] args)
        {
            var ips   = GetRandomIps(20);
            var words = GetRandomWords(20);

            var threads = new List <Thread>();

            foreach (var ip in ips)
            {
                var ip1 = ip;
                var t   = new Thread(() =>
                {
                    Console.WriteLine("Checking ip " + ip1);
                    IpResults.R.Add(new IpResult(ip1)
                    {
                        HostName = GetHostName(ip1),
                        CanPing  = Ping(ip1)
                    });
                });
                threads.Add(t);
                t.Start();
            }

            foreach (var word in words)
            {
                var word1 = word;
                var t     = new Thread(() =>
                {
                    Console.WriteLine("Checking word " + word1);
                    var r      = new DnsResult(word1);
                    r.HostName = r.PossibleDns.Select(GetHostName).FirstOrDefault(x => x != null);
                    r.CanPing  = r.PossibleDns.Select(Ping).FirstOrDefault(x => x);
                    DnsResults.R.Add(r);
                });
                threads.Add(t);
                t.Start();
            }

            foreach (var thread in threads.Where(thread => thread != null && thread.ThreadState != ThreadState.Stopped))
            {
                thread.Join();
            }

            Console.WriteLine("IP Address\tHasDns\tCanPing\t");
            foreach (var result in IpResults.R)
            {
                Console.WriteLine("{0} {1} {2}", result.IpOrWord, result.HasDns, result.CanPing);
            }

            Console.WriteLine("Word\tHasDns\tCanPing\t");
            foreach (var result in DnsResults.R)
            {
                Console.WriteLine("{0} {1} {2}", result.IpOrWord, result.HasDns, result.CanPing);
            }

            Console.Write("******** TOTALS **********");
            Console.WriteLine("IP % with DNS: " + IpResults.PercentWithDns);
            Console.WriteLine("IP % with Ping: " + IpResults.PercentPingable);
            Console.WriteLine("IP % with Both: " + IpResults.PercentBoth);
            Console.WriteLine("DNS % with DNS: " + DnsResults.PercentWithDns);
            Console.WriteLine("DNS % with Ping: " + DnsResults.PercentPingable);
            Console.WriteLine("DNS % with Both: " + DnsResults.PercentBoth);
            Console.ReadKey();
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var ips = GetRandomIps(20);
            var words = GetRandomWords(20);

            var threads = new List<Thread>();

            foreach (var ip in ips)
            {
                var ip1 = ip;
                var t = new Thread(() =>
                {
                    Console.WriteLine("Checking ip " + ip1);
                    IpResults.R.Add(new IpResult(ip1)
                        {
                            HostName = GetHostName(ip1),
                            CanPing = Ping(ip1)
                        });
                });
                threads.Add(t);
                t.Start();
            }

            foreach (var word in words)
            {
                var word1 = word;
                var t = new Thread(() =>
                {
                    Console.WriteLine("Checking word " + word1);
                    var r = new DnsResult(word1);
                    r.HostName = r.PossibleDns.Select(GetHostName).FirstOrDefault(x => x != null);
                    r.CanPing = r.PossibleDns.Select(Ping).FirstOrDefault(x => x);
                    DnsResults.R.Add(r);
                });
                threads.Add(t);
                t.Start();
            }

            foreach (var thread in threads.Where(thread => thread != null && thread.ThreadState != ThreadState.Stopped))
            {
                thread.Join();
            }

            Console.WriteLine("IP Address\tHasDns\tCanPing\t");
            foreach (var result in IpResults.R)
            {
                Console.WriteLine("{0} {1} {2}", result.IpOrWord, result.HasDns, result.CanPing);
            }

            Console.WriteLine("Word\tHasDns\tCanPing\t");
            foreach (var result in DnsResults.R)
            {
                Console.WriteLine("{0} {1} {2}", result.IpOrWord, result.HasDns, result.CanPing);
            }

            Console.Write("******** TOTALS **********");
            Console.WriteLine("IP % with DNS: " + IpResults.PercentWithDns);
            Console.WriteLine("IP % with Ping: " + IpResults.PercentPingable);
            Console.WriteLine("IP % with Both: " + IpResults.PercentBoth);
            Console.WriteLine("DNS % with DNS: " + DnsResults.PercentWithDns);
            Console.WriteLine("DNS % with Ping: " + DnsResults.PercentPingable);
            Console.WriteLine("DNS % with Both: " + DnsResults.PercentBoth);
            Console.ReadKey();
        }