首页 > 开发 > 综合 > 正文

C#域名查询

2024-07-21 02:25:01
字体:
来源:转载
供稿:网友
queryinternic.aspx

<% @page language="c#" %>
<% @import namespace="system.net.sockets" %>
<% @import namespace="system.text" %>
<% @import namespace="system.io" %>
<%
tcpclient tcpc = new tcpclient();
try
{
tcpc.connect("whois.networksolutions.com", 43);
}
catch(socketexception ex)
{
response.write(ex.tostring());
response.end();
}

string strdomain = "gotdotnet.com/r/n";
byte[] arrdomain = encoding.ascii.getbytes(strdomain.tochararray());

stream s = tcpc.getstream();
s.write(arrdomain, 0, strdomain.length);

streamreader sr = new streamreader(tcpc.getstream(), encoding.ascii);
string strline = null;

while (null != (strline = sr.readline()))
{
response.write(strline + "<br>");
}

tcpc.close();
%>


queryregistries.aspx

<% @page language="c#" %>
<% @import namespace="system.net.sockets" %>
<% @import namespace="system.text" %>
<% @import namespace="system.io" %>
<% @import namespace="system.collections" %>
<script language="c#" runat="server">
void doquery(object sender, eventargs e)
{
string strdomain = txtdomain.text;
char[] chsplit = {'.'};
string[] arrdomain = strdomain.split(chsplit);
// es darf genau ein domain name + ein suffix sein
if (arrdomain.length != 2)
{
return;
}

// das suffic darf nur 2 oder 3 zeichen lang sein
int nlength = arrdomain[1].length;
if (nlength != 2 && nlength != 3)
{
return;
}

hashtable table = new hashtable();
table.add("at", "whois.nic.at");
table.add("de", "whois.denic.de");
table.add("be", "whois.dns.be");
table.add("gov", "whois.nic.gov");
table.add("mil", "whois.nic.mil");

string strserver = "whois.networksolutions.com";
if (table.containskey(arrdomain[1]))
{
strserver = table[arrdomain[1]].tostring();
}
else if (nlength == 2)
{
// 2-letter tld's always default to ripe in europe
strserver = "whois.ripe.net";
}

string strresponse;
bool bsuccess = dowhoislookup(strdomain, strserver, out strresponse);
if (bsuccess)
{
txtresult.text = strresponse;
}
else
{
txtresult.text = "lookup failed";
}
}

bool dowhoislookup(string strdomain, string strserver, out string strresponse)
{
strresponse = "none";
bool bsuccess = false;

tcpclient tcpc = new tcpclient();
try
{
tcpc.connect(strserver, 43);
}
catch(socketexception ex)
{
strresponse = "could not connect to whois server";
return false;
}

strdomain += "/r/n";
byte[] arrdomain = encoding.ascii.getbytes(strdomain.tochararray());
try
{
stream s = tcpc.getstream();
s.write(arrdomain, 0, strdomain.length);

streamreader sr = new streamreader(tcpc.getstream(), encoding.ascii);
stringbuilder strbuilder = new stringbuilder();
string strline = null;

while (null != (strline = sr.readline()))
{
strbuilder.append(strline+"<br>");
}
tcpc.close();

bsuccess = true;
strresponse = strbuilder.tostring();
}
catch(exception e)
{
strresponse = e.tostring();
}

return bsuccess;
}
</script>
<html>
<head>
<title></title>
</head>
<body>

<form runat="server">
domain name: <asp:textbox id="txtdomain" value="aspheute.com" runat="server" />
&nbsp;<asp:button id="btnquery" onclick="doquery" text="query!" runat="server" />
<br><hr width="100%"><br>
<asp:label id="txtresult" runat="server" />
</form>

</body>
</html>




商业源码热门下载www.html.org.cn

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表