修改后的Whois查询程序
2024-07-21 02:24:49
供稿:网友
<% @page language="c#" %>
<% @import namespace="system.net" %>
<% @import namespace="system.net.sockets" %>
<% @import namespace="system.text" %>
<% @import namespace="system.io" %>
<% @import namespace="system.collections" %>
<html>
<head>
<title>whois查询</title>
<link href="../inc/main.css" type="text/css" rel="stylesheet">
<script language="c#" runat="server">
void doquery(object sender, eventargs e)
{
string strdomain;
string strserver;
//strserver = "whois.paycenter.com.cn";
//新网的whois,联接查询速度较快,但不是在新网注册的域名可能无法显示详细资料
strserver = "66.150.5.140"; //whois.uwhois.com
if(txtdomain2.checked)
{ strdomain = txtdomain1.text+txtdomain2.text; }
else
{
if(txtdomain3.checked)
{ strdomain = txtdomain1.text+txtdomain3.text; }
else
{
if(txtdomain4.checked)
{ strdomain = txtdomain1.text+txtdomain4.text; }
else
{
if(txtdomain5.checked)
{ strdomain = txtdomain1.text+txtdomain5.text; }
else
{ strdomain = txtdomain1.text+txtdomain6.text; }
}
}
}
string strresponse;
bool bsuccess = dowhoislookup(strdomain, strserver, out strresponse);
if (bsuccess)
{
txtresult.text = strresponse;
}
else
{
txtresult.text = "查询失败!请重试。";
}
}
bool dowhoislookup(string strdomain, string strserver, out string strresponse)
{
strresponse = "none";
bool bsuccess = false;
tcpclient tcpc = new tcpclient();
tcpc.connect(strserver, 43);
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();
while (-1 != sr.peek())
{
strbuilder.append(sr.readline()+"<br>");
}
tcpc.close();
bsuccess = true;
strresponse = strbuilder.tostring();
}
catch(exception e)
{
strresponse = e.tostring();
}
return bsuccess;
}
</script>
</head>
<body>
<form runat="server">
域名: www.<asp:textbox id="txtdomain1" value="" runat="server" />
<asp:radiobutton id="txtdomain2" groupname="radiogroup1" text=".com" checked="true" runat="server" />
<asp:radiobutton id="txtdomain3" groupname="radiogroup1" text=".net" runat="server" />
<asp:radiobutton id="txtdomain4" groupname="radiogroup1" text=".org" runat="server" />
<asp:radiobutton id="txtdomain5" groupname="radiogroup1" text=".biz" runat="server" />
<asp:radiobutton id="txtdomain6" groupname="radiogroup1" text=".cc" runat="server" />
<asp:button id="btnquery" onclick="doquery" text="查询" runat="server" />
<br><hr width="100%"><br>
<asp:label id="txtresult" forecolor="#0000ff" class="body" runat="server" />
</form>
</body>
</html>