Esempio n. 1
0
        private void Resolver_Button_Click(object sender, EventArgs e)
        {
            string data = Resolver_InputTB.Text;

            string[] buffer = new string[Resolver_listView.Columns.Count];

            IPAddress ip;

            if (IPAddress.TryParse(data, out ip))
            {
                string domain = NTResolver.IPToDomain(ip);
                buffer[0] = ip.ToString();
                buffer[1] = data;
                Resolver_listView.Items.Add(new ListViewItem(buffer));
            }
            else
            {
                IPAddress[] list = NTResolver.DomainToIP(data);
                foreach (var item in list)
                {
                    buffer[0] = data;
                    buffer[1] = item.ToString();
                    Resolver_listView.Items.Add(new ListViewItem(buffer));
                }
            }
        }
Esempio n. 2
0
        public static IEnumerable <RouteInfo> GetTraceRoute(string hostname)
        {
            const int timeout    = 10000;
            const int maxTTL     = 30;
            const int bufferSize = 32;

            byte[] buffer = new byte[bufferSize];
            Ping   pinger = new Ping();

            for (int ttl = 1; ttl <= maxTTL; ttl++)
            {
                Stopwatch   stopWatch = new Stopwatch();
                PingOptions options   = new PingOptions(ttl, true);

                stopWatch.Start();
                PingReply reply = pinger.Send(hostname, timeout, buffer, options);
                stopWatch.Stop();

                switch (reply.Status)
                {
                case IPStatus.TtlExpired:
                    yield return(new RouteInfo(stopWatch.ElapsedMilliseconds, reply.Address, NTResolver.IPToDomain(reply.Address)));

                    continue;

                case IPStatus.TimedOut:
                    continue;

                case IPStatus.Success:
                    yield return(new RouteInfo(stopWatch.ElapsedMilliseconds, reply.Address, NTResolver.IPToDomain(reply.Address)));

                    break;
                }

                break;
            }
        }