欢迎光临
我们一直在努力

C#域名查询-.NET教程,C#语言

建站超值云服务器,限时71元/月

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 tlds 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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » C#域名查询-.NET教程,C#语言
分享到: 更多 (0)