using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          using System.Windows.Forms;
          namespace CheckDomain
          {

              using System.Net;
              using System.IO;
              using System.Text.RegularExpressions;
              using System.Collections;
              public delegate void CallBack(DataGridViewRow dgrv, DomainStatus ds);
              public delegate void CallBackEx(string dgrv, DomainStatus ds);
              public class ThreadWithData
              {
                  public UrlCheck uc = new UrlCheck();
                  public CallBack CBack;
                  public CallBackEx CBackEx;
                  public ArrayList DomainList;
                  public DataGridViewRow[] DataGridViewRowDomainList;

                  public ThreadWithData(ArrayList tempDomain, CallBack tempCBack)
                  {
                      this.CBack = tempCBack;
                      this.DomainList = tempDomain;

                  }
                  public ThreadWithData(DataGridViewRow[] tempDataGridViewRowDomainList, CallBack tempCBack)
                  {
                      this.CBack = tempCBack;
                      this.DataGridViewRowDomainList = tempDataGridViewRowDomainList;

                  }
                  public ThreadWithData(ArrayList tempDomain, CallBackEx tempCBack)
                  {
                      this.CBackEx = tempCBack;
                      this.DomainList = tempDomain;

                  }
                  public void Run()
                  {
                      foreach (DataGridViewRow tempDomain in DomainList)
                      {

                          DomainStatus tempDS = uc.GetDomainStatus(tempDomain.Cells["Column2"].Value.ToString());
                          CBack(tempDomain, tempDS);
                          //CBack(tempDS.Status);
                      }
                  }
                  public void RunMy()
                  {
                      foreach (DataGridViewRow tempDomain in DomainList)
                      {

                          DomainStatus tempDS = uc.GetDomainStatus(tempDomain.Cells["Column12"].Value.ToString());
                          CBack(tempDomain, tempDS);
                          //CBack(tempDS.Status);
                      }
                  }
                  public void RunGrid()
                  {
                      foreach (DataGridViewRow tempDomain in DataGridViewRowDomainList)
                      {

                          DomainStatus tempDS = uc.GetDomainStatus(tempDomain.Cells["Column2"].Value.ToString());
                          CBack(tempDomain, tempDS);
                      }
                  }
                  public void RunEx()
                  {
                      foreach (string tempDomain in DomainList)
                      {

                          DomainStatus tempDS = uc.GetDomainStatus(tempDomain);
                          CBackEx(tempDomain, tempDS);
                          //CBack(tempDS.Status);
                      }
                  }
              }
              public class DomainStatus
              {
                  public bool Status;
                  public DateTime Create_Date;
                  public DateTime Updated_Date;
                  public DateTime Expiration_Date;
              }
              public class UrlCheck
              {
                  public string GetHttpData(string sUrl, string charset)
                  {
                      string sRslt = null;
                      WebResponse oWebRps = null;
                      WebRequest oWebRqst = WebRequest.Create(sUrl);
                      oWebRqst.Timeout = 50000;
                      try
                      {
                          oWebRps = oWebRqst.GetResponse();
                      }

                      finally
                      {
                          if (oWebRps != null)
                          {
                              StreamReader oStreamRd = new StreamReader(oWebRps.GetResponseStream(), System.Text.Encoding.GetEncoding(charset));
                              sRslt = oStreamRd.ReadToEnd();
                              oStreamRd.Close();
                              oWebRps.Close();
                          }
                      }
                      return sRslt;
                  }
                  //
                  //Updated Date: 25-mar-2010
                  //Creation Date: 23-apr-1996
                  //Expiration Date: 24-apr-2019
                  public DomainStatus GetDomainStatus(string domain)
                  {
                      DomainStatus tempDomainStatus = new DomainStatus();
                      string tempContent = "";
                      try
                      {
                          tempContent= GetHttpData("            }
                      catch (Exception ex)
                      {
                          tempContent = "";
                         
                      }
                      string[] tempCdate = GetRegValue(tempContent, "Creation Date:(?<cdate>([^\\n]+))", "cdate", true);

                      if (tempCdate.Length > 0)
                      {
                          string[] tempUpdate = GetRegValue(tempContent, "Updated Date:(?<udate>([^\\n]+))", "udate", true);
                          string[] tempEdate = GetRegValue(tempContent, "Expiration Date:(?<edate>([^\\n]+))", "edate", true);
                          DateTime dt1 = DateTime.Parse(tempCdate[0]);
                          DateTime dt2 = DateTime.Parse(tempUpdate[0]);
                          DateTime dt3 = DateTime.Parse(tempEdate[0]);
                          tempDomainStatus.Status = true;
                          tempDomainStatus.Create_Date = dt1;
                          tempDomainStatus.Updated_Date = dt2;
                          tempDomainStatus.Expiration_Date = dt3;
                      }
                      else
                      {
                          tempDomainStatus.Status = false;
                      }
                      return tempDomainStatus;

                  }
                  /// <summary>
                  /// 正則表達式取值
                  /// </summary>
                  /// <param name="HtmlCode">源碼</param>
                  /// <param name="RegexString">正則表達式</param>
                  /// <param name="GroupKey">正則表達式分組關鍵字</param>
                  /// <param name="RightToLeft">是否從右到左</param>
                  /// <returns></returns>
                  public string[] GetRegValue(string HtmlCode, string RegexString, string GroupKey, bool RightToLeft)
                  {
                      MatchCollection m;
                      Regex r;
                      if (RightToLeft == true)
                      {
                          r = new Regex(RegexString, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.RightToLeft);
                      }
                      else
                      {
                          r = new Regex(RegexString, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                      }
                      m = r.Matches(HtmlCode);
                      string[] MatchValue = new string[m.Count];
                      for (int i = 0; i < m.Count; i++)
                      {
                          MatchValue[i] = m[i].Groups[GroupKey].Value;
                      }
                      return MatchValue;
                  }
                  public string[] GetRegValue1(string HtmlCode, string RegexString, string GroupKey, bool RightToLeft)
                  {
                      MatchCollection m;
                      Regex r;
                      if (RightToLeft == true)
                      {
                          r = new Regex(RegexString, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.RightToLeft);
                      }
                      else
                      {
                          r = new Regex(RegexString, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                      }
                      m = r.Matches(HtmlCode);
                      string[] MatchValue = new string[m.Count];
                      for (int i = 0; i < m.Count; i++)
                      {
                          MatchValue[i] = m[i].Groups[GroupKey].Value;
                      }
                      return MatchValue;
                  }

              }
          }


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 伊川县| 乌拉特中旗| 东阿县| 乡城县| 平湖市| 仙桃市| 宣威市| 瑞金市| 搜索| 赤壁市| 库伦旗| 古蔺县| 江阴市| 江油市| 祁连县| 无为县| 德昌县| 龙口市| 易门县| 莎车县| 博野县| 武乡县| 翁牛特旗| 得荣县| 茂名市| 洪雅县| 修文县| 凤台县| 山东省| 常宁市| 安福县| 惠安县| 固安县| 白水县| 平舆县| 宜兰市| 浮梁县| 南陵县| 澜沧| 仙游县| 南乐县|