Пример #1
0
        private void UpdateIPAddress(IPHostEntry dnsEntry)
        {
            if (InvokeRequired)
            {
                Invoke(new UpdateIPAddressDelegate(UpdateIPAddress), dnsEntry);
                return;
            }

            if (dnsEntry.AddressList.Length > 1)
            {
                ChooseIPForm dlg = new ChooseIPForm();
                if (dlg.ShowDialog(this, dnsEntry.AddressList) == DialogResult.OK)
                {
                    _tbHostIp.Text = dlg.SelectedIPAddress.ToString();
                }
            }
            else
            {
                _tbHostIp.Text = dnsEntry.AddressList[0].ToString();
            }
        }
Пример #2
0
        private void _btnTrace_Click(object sender, EventArgs e)
        {
            if (_tracer.Active)
            {
                _tracer.Stop(false);
                return;
            }

            try
            {
                IPHostEntry entry = Dns.GetHostEntry(_tbTarget.Text);

                if (entry.AddressList.Length > 1)
                {
                    ChooseIPForm dlg = new ChooseIPForm();
                    if (dlg.ShowDialog(this, entry.AddressList) == DialogResult.OK)
                    {
                        _tracer.Target = dlg.SelectedIPAddress;
                    }
                }
                else
                {
                    _tracer.Target = entry.AddressList[0];
                }

                _tracer.Start();
            }
            catch (SocketException)
            {
                MessageBox.Show(this, "Cannot resolve host name!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch
            {
                MessageBox.Show(this, "Cannot parse host name or IP address!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }