コード例 #1
0
 private void btnCheck1_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (!IsValidHttp(txDomain1.Text.Trim()))
         {
             UMessageBox.Show("提示", "域名格式不正确!请重新输入。");
             return;
         }
         if (ckDNSserver.IsChecked == true)
         {
             if (!IsValidIp(txDNSserver.Text.Trim()))
             {
                 UMessageBox.Show("提示", "DNS格式不正确!请重新输入。");
                 return;
             }
             else
             {
                 _dnsname = txDNSserver.Text;
             }
         }
         else
         {
             if (cbDNSserver.SelectedIndex == 0)
             {
                 NetworkInterface[]    adapters          = NetworkInterface.GetAllNetworkInterfaces();
                 IPInterfaceProperties adapterProperties = adapters[0].GetIPProperties();
                 _dnsname = adapterProperties.DnsAddresses[0].ToString();
             }
             else
             {
                 int m = cbDNSserver.SelectedValue.ToString().IndexOf("(");
                 int n = cbDNSserver.SelectedValue.ToString().IndexOf(")");
                 _dnsname = cbDNSserver.SelectedValue.ToString().Substring(m + 1, n - m - 1);
             }
         }
         state = 1;
         _host = txDomain1.Text;
         btnCheck1.Visibility  = Visibility.Hidden;
         _btnCheck1.Visibility = Visibility.Visible;
         timer.Start();
         dt.Clear();
         bw = new BackgroundWorker();
         bw.WorkerReportsProgress      = true;
         bw.WorkerSupportsCancellation = true;
         bw.DoWork          += bw_DoWork;
         bw.ProgressChanged += bw_ProgressChanged;
         bw.RunWorkerAsync(0);
     }
     catch (Exception ex)
     {
         UMessageBox.Show("异常提示", " 无法处理请求,因为以下问题发生:\n" + ex.Message);  //这里是异常处理  例如网络连接或主机不能解析等其它问题就显示出来给用户
     }
 }
コード例 #2
0
 private void bw_DoWork(object sender, DoWorkEventArgs e)
 {
     if (bw.CancellationPending)
     {
         return;
     }
     else
     {
         dt.Rows.Add("DNS记录", "记录类型", "解析结果", "TTL");
         MyDns mydns = new MyDns();
         if (!mydns.Search(_host, QueryType.A, _dnsname, null))
         {
             UMessageBox.Show("提示", mydns.header.RCODE.ToString());
             return;
         }
         foreach (MyDnsRecord item in mydns.record.Records)
         {
             dt.Rows.Add(item.Name, item.QType.ToString(), item.RDDate.ToString().Replace(" ", ""), item.TTL.ToString());
         }
         if (!mydns.Search(_host, QueryType.MX, _dnsname, null))
         {
             UMessageBox.Show("提示", mydns.header.RCODE.ToString());
             return;
         }
         foreach (MyDnsRecord item in mydns.record.Records)
         {
             dt.Rows.Add(item.Name, item.QType.ToString(), item.RDDate.ToString().Replace(" ", "").Replace('|', '\r'), item.TTL.ToString());
         }
         if (!mydns.Search(_host, QueryType.CNAME, _dnsname, null))
         {
             UMessageBox.Show("提示", mydns.header.RCODE.ToString());
             return;
         }
         foreach (MyDnsRecord item in mydns.record.Records)
         {
             dt.Rows.Add(item.Name, item.QType.ToString(), item.RDDate.ToString().Replace(" ", "").Replace('|', '\r'), item.TTL.ToString());
         }
         if (!mydns.Search(_host, QueryType.TXT, _dnsname, null))
         {
             UMessageBox.Show("提示", mydns.header.RCODE.ToString());
             return;
         }
         foreach (MyDnsRecord item in mydns.record.Records)
         {
             dt.Rows.Add(item.Name, item.QType.ToString(), item.RDDate.ToString().Replace(' ', '\r'), item.TTL.ToString());
         }
         bw.ReportProgress(100);
     }
 }
コード例 #3
0
 private void btnCheck2_Click(object sender, RoutedEventArgs e)
 {
     if (!IsValidHttp(txDomain2.Text.Trim()))
     {
         UMessageBox.Show("提示", "域名格式不正确!请重新输入。");
         return;
     }
     state = 1;
     _host = txDomain2.Text;
     btnCheck2.Visibility  = Visibility.Hidden;
     _btnCheck2.Visibility = Visibility.Visible;
     bw1 = new BackgroundWorker();
     bw1.WorkerReportsProgress      = true;
     bw1.WorkerSupportsCancellation = true;
     bw1.DoWork          += bw_DoWork2;
     bw1.ProgressChanged += bw_ProgressChanged2;
     bw1.RunWorkerAsync(0);
 }