Esempio n. 1
0
        /// <summary>
        /// 提取邮政地址(某某市某某街道某某楼某房间)
        /// </summary>
        /// <param name="inputText">输入文本</param>
        /// <returns></returns>
        public static string GetPostAddress(string inputText)
        {
            string taddress = TextTool.StripHTML(inputText);
            Match  myMatch  = Regex.Match(taddress, @"[\u4e00-\u9fa5\d-()()\w]{0,200}");

            if (myMatch.Success)
            {
                taddress = myMatch.Value;
            }
            else
            {
                taddress = "";
            }
            return(taddress);
        }
Esempio n. 2
0
        /// <summary>
        /// 查询Whois 信息
        /// </summary>
        /// <param name="domain">域名</param>
        /// <returns></returns>
        public static string SearchAWhois(string domain)
        {
            #region 查询Whois信息
            string pageHtml = "";
            string infoReg  = "";
            string getUrl   = "";

            infoReg = @"<div class=""main"">(?<whoinfo>(.|\n)+?)<div class=""footer"">";
            getUrl  = string.Format("http://whoissoft.com/{0}", domain);

            try
            {
                WebRequest     request  = WebRequest.Create(getUrl);
                HttpWebRequest hRequest = (HttpWebRequest)request;
                hRequest.AllowAutoRedirect = true;
                hRequest.KeepAlive         = true;
                //hRequest.Headers.Add("Host:whois.chinaz.com");
                //hRequest.Headers.Add("Content-Type:text/html;charset=utf-8");
                hRequest.ContentType = "text/html;charset=utf-8";
                hRequest.Headers.Add("Cache-Control: private");
                hRequest.UserAgent = "Laopei";
                hRequest.Headers.Add("Server: Microsoft-IIS/6.0");
                hRequest.Headers.Add("X-Powered-By: ASP.NET");
                hRequest.Headers.Add("X-AspNet-Version: 2.0.50727");

                HttpWebResponse response;
                try
                {
                    response = (HttpWebResponse)hRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    response = (HttpWebResponse)ex.Response;
                }

                Stream       dataStream = response.GetResponseStream();
                StreamReader reader     = new StreamReader(dataStream, Encoding.GetEncoding("utf-8"));
                pageHtml = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
                response.Close();

                //如果是从WhoisSoft查询,则清除内容中的链接
                pageHtml = TextTool.StripHtmlClearTagA(pageHtml);

                var    regResult = Regex.Match(pageHtml, infoReg, RegexOptions.IgnoreCase);
                string whois1    = "";

                if (regResult.Success)
                {
                    whois1 = regResult.Groups["whoinfo"].Value;
                }

                return(whois1);
            }
            catch (Exception ex)
            {
                var x = ex.Message;
            }

            return("查询失败!");

            #endregion
        }