ASP.NET域名查询系统
2024-07-10 12:57:06
供稿:网友
,欢迎访问网页设计爱好者web开发。<% @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.aspxboy.com/" title=/".net男孩社区/">www.aspxboy.com</a><br>";
strresponse = strbuilder.tostring()+my; }
catch(exception e)
{
strresponse = e.tostring();
}
return blsuccess;
}
</script>