日期:2010-11-27 10:45:00 来源:本站整理
ASP.NET实现域名whois信息查询[网站编程]
本文“ASP.NET实现域名whois信息查询[网站编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
cs 代码以下,也有大概因为服务器不可用招致查询失利!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using System.Net.Sockets;
- using System.Text.RegularExpressions;
- using System.Globalization;
- public partial class Default2 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- public static string Mywhois(string _domain)
- {
- string strServerReal = "";
- string strServerCom = "whois.internic.net";
- string strServerCN = "whois.cnnic.net.cn";
- string strServerLA = "whois2.afilias-grs.net";
- string strServerORG = "whois.publicinterestregistry.net";
- string strServerCC = "whois.nic.cc";
- string strServerTV = "whois.nic.tv";
- string strServerBIZ = "whois.neulevel.biz";
- string strServerMOBI = "whois.dotmobiregistry.net";
- string strServerINFO = "whois.afilias.net";
- string strServerTW = "whois.twnic.net";
- string strServerNAME = "whois.nic.Name";
- bool blSuccess = false, blSuccess1 = false;
- String strResponse = "", strResponse1;
- _domain = _domain.Replace("http://", "");
- _domain = _domain.Replace("www.", "");
- if (Regex.IsMatch(_domain, @"[\u4e00-\u9fa5]+"))
- {
- IdnMapping dd = new IdnMapping();
- _domain = dd.GetAscii(_domain);
- }
- string[] arrDomain = _domain.Split('.');
- string DomainType = arrDomain[arrDomain.GetLength(0) - 1].ToUpper();
- if (DomainType == "CN")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerCN, out strResponse);
- }
- else if (DomainType == "TW")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerTW, out strResponse);
- }
- else if (DomainType == "LA")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerLA, out strResponse);
- }
- else if (DomainType == "CC")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerCC, out strResponse);
- }
- else if (DomainType == "TV")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerTV, out strResponse);
- }
- else if (DomainType == "BIZ")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerBIZ, out strResponse);
- }
- else if (DomainType == "MOBI")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerMOBI, out strResponse);
- }
- else if (DomainType == "INFO")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerINFO, out strResponse);
- }
- else if (DomainType == "NAME")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerNAME, out strResponse);
- }
- else if (DomainType == "ORG")
- {
- blSuccess = IsWhosisSuccess(_domain, strServerORG, out strResponse);
- }
- else
- {
- blSuccess = IsWhosisSuccess(_domain, strServerCom, out strResponse1);
- int ii = strResponse1.IndexOf("Whois Server:");
- if ((ii >= 0) && (blSuccess))
- {
- strServerReal = strResponse1.Remove(0, strResponse1.IndexOf("Whois Server:"));
- strServerReal = strServerReal.Remove(strServerReal.IndexOf("\r\n"), strServerReal.Length - strServerReal.IndexOf("\r\n"));
- strServerReal = strServerReal.Remove(0, strServerReal.IndexOf(":") + 1);
- strServerReal = strServerReal.Trim();
- blSuccess1 = IsWhosisSuccess(_domain, strServerReal, out strResponse);
- if (!blSuccess1)
- {
- strResponse = "[" + strServerCom + "]" + "\r\n" + strResponse1;
- }
- else
- {
- strResponse = "[" + strServerReal + "]" + "\r\n" + strResponse;
- }
- }
- else
- {
- strResponse = "[" + strServerCom + "]" + "\r\n" + strResponse1;
- }
- }
- if (blSuccess)
- {
- return strResponse;
- }
- else
- {
- return "查询失利....";
- }
- }
- private static bool IsWhosisSuccess(String strDomain, String strServer,
- out String strResponse)
- {
- strResponse = "none";
- if ((strDomain == "") || (strDomain == null) || (strServer == "") || (strServer == null))
- throw new ArgumentNullException();
- bool blSuccess = false;
- TcpClient tcpc = new TcpClient();
- try
- {
- tcpc.Connect(strServer, 43);
- }
- catch
- {
- strResponse = "[" + strServer + "]" + "\r\n" + "衔接不到该 Whois server,请稍后再试.";
- return false;
- }
- strDomain += "\r\n";
- Byte[] arrDomain = Encoding.UTF8.GetBytes(strDomain.ToCharArray());
- try
- {
- Stream s = tcpc.GetStream();
- s.Write(arrDomain, 0, strDomain.Length);
- StreamReader sr = new StreamReader(tcpc.GetStream(), Encoding.UTF8);
- StringBuilder strBuilder = new StringBuilder();
- string strLine = null;
- while (null != (strLine = sr.ReadLine()))
- {
- strBuilder.Append(strLine + "\r\n");
- }
- tcpc.Close();
- blSuccess = true;
- strResponse = strBuilder.ToString();
- }
- catch (Exception e)
- {
- strResponse = e.ToString();
- return false;
- }
- return blSuccess;
- }
- protected void btn_Query_Click(object sender, EventArgs e)
- {
- lbl_whoisinfo.Text = Mywhois(TextBox1.Text.Trim());
- }
- }
以上是“ASP.NET实现域名whois信息查询[网站编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论