Whois查询ASP.NET C# 源码 查询域名信息

域名Whois查询ASP.NET C# 源码 增加了.CN查询功能
 

增加了CN查询功能

CODE:
[url=###][Copy to clipboard][/url]
<% @Page Language="C#" %>
<% @Import Namespace="System.Net.Sockets" %>
<% @Import Namespace="System.Text" %>
<% @Import Namespace="System.IO" %>
<html>
<head>
<title>.Com/.Net/.Org/.Cn 域名Whois信息查询</title>
<meta name="keywords" content=".Com,.Net,.Org,.Cn 域名Whois信息查询">
<meta name="generator" content=".Com/.Net/.Org,.Cn 域名Whois信息查询">
<meta name="description" content=".Com/.Net/.Org,.Cn 域名Whois信息查询">
<style>
<!--
body,input{
    font-family: Tahoma, Verdana; color: #004080; font-size: 12px       
    }
a:link,a:visited{ 
    text-decoration: none; color: #004080 
    }
-->
</style>
</head>
<body>
<form id="fmQuery" runat="server">
要查询的域名域名: 
www.<asp:TextBox  id="txtDomain" width="100" value="ASPXBOY.COM" runat="server" />
<asp:Button id="btnQuery" OnClick="btn_click" 
text="查询!" runat="server" />(只能查询.Com/.Net/.Org/.Cn 域名Whois的信息)     <a href ="WhoisCode.htm" title="View the source code here!">源代码在这里</a>
<BR><HR width="550" height="1" align="left"><BR>
<asp:label id="lblResult" runat="server" />
</form>
</body>
</html>
<script language="C#" runat="server">
void btn_click(Object sender, EventArgs e)
{
String strServer;
String strDomain = txtDomain.Text; 
String strServerCom = "whois.networksolutions.com"; 
String strServerCN = "whois.cnnic.net.cn";
String strResponse;
string[] arrDomain = strDomain.Split('.');
if (arrDomain[1].ToUpper()=="CN")
{
    
    strServer=strServerCN;
}
else
{
    strServer=strServerCom;
}

bool blSuccess = IsWhosisSuccess(strDomain, strServer, out strResponse);
if (blSuccess)
{
lblResult.Text = strResponse;
}
else
{
lblResult.Text = "查找失败....";
}
}
bool IsWhosisSuccess(String strDomain, String strServer, 
            out String strResponse)
{
strResponse = "none";
bool blSuccess = false;
TcpClient tcpc = new TcpClient();
try
{
  tcpc.Connect(strServer, 43);
}
catch(SocketException ex)
{
  strResponse = "连接不到该 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 "<br>");
    }
    tcpc.Close();
          
    blSuccess = true;
    string my="Go to Huobazi's WebSite:<a href=/"
http://www.zh-zy.com /" title=/"http://www.zh-zy.com/"> http://www.zh-zy.com</a><br>";
    strResponse = strBuilder.ToString() my; }
catch(Exception e)
{
    strResponse = e.ToString();
}

return blSuccess;
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值