C#独立域名查询代码_C#教程-查字典教程网
C#独立域名查询代码
C#独立域名查询代码
发布时间:2016-12-28 来源:查字典编辑
摘要:whois.aspxvoiddoQuery(Objectsender,EventArgse){StringstrDomain=txtDoma...

whois.aspx

<%@PageLanguage="C#"%>

<%@ImportNamespace="System.Net.Sockets"%>

<%@ImportNamespace="System.Text"%>

<%@ImportNamespace="System.IO"%>

<%@ImportNamespace="System.Collections"%>

<scriptlanguage="C#"runat="server">

voiddoQuery(Objectsender,EventArgse)

{

StringstrDomain=txtDomain.Text;

char[]chSplit={'.'};

string[]arrDomain=strDomain.Split(chSplit);

//esdarfgenaueindomainname+einsuffixsein

if(arrDomain.Length!=2)

{

return;

}

//dassufficdarfnur2oder3zeichenlangsein

intnLength=arrDomain[1].Length;

if(nLength!=2&&nLength!=3)

{

return;

}

Hashtabletable=newHashtable();

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");

StringstrServer="whois.OnlineNIC.com";

if(table.ContainsKey(arrDomain[1]))

{

strServer=table[arrDomain[1]].ToString();

}

elseif(nLength==2)

{

//2-letterTLD'salwaysdefaulttoRIPEinEurope

strServer="whois.ripe.net";

}

StringstrResponse;

boolbSuccess=DoWhoisLookup(strDomain,strServer,outstrResponse);

if(bSuccess)

{

txtResult.Text=strResponse;

}

else

{

txtResult.Text="Lookupfailed";

}

}

boolDoWhoisLookup(StringstrDomain,StringstrServer,outStringstrResponse)

{

strResponse="none";

boolbSuccess=false;

TcpClienttcpc=newTcpClient();

try

{

tcpc.Connect(strServer,43);

}

catch(SocketExceptionex)

{

strResponse="CouldnotconnecttoWhoisserver";

returnfalse;

}

strDomain+="rn";

Byte[]arrDomain=Encoding.ASCII.GetBytes(strDomain.ToCharArray());

try

{

Streams=tcpc.GetStream();

s.Write(arrDomain,0,strDomain.Length);

StreamReadersr=newStreamReader(tcpc.GetStream(),Encoding.ASCII);

StringBuilderstrBuilder=newStringBuilder();

stringstrLine=null;

while(null!=(strLine=sr.ReadLine()))

{

strBuilder.Append(strLine+"<br>");

}

tcpc.Close();

bSuccess=true;

strResponse=strBuilder.ToString();

}

catch(Exceptione)

{

strResponse=e.ToString();

}

returnbSuccess;

}

</script>

<html>

<head>

<title></title>

</head>

<body>

<formrunat="server">

域名whois查询(.NET版):<asp:TextBoxid="txtDomain"value="3cts.com"runat="server"/>

<asp:Buttonid="btnQuery"OnClick="doQuery"text="Query!"runat="server"/>

<BR><HRwidth="100%"><BR>

<asp:labelid="txtResult"runat="server"/>

</form>

</body>

</html>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新C#教程学习
    热门C#教程学习
    编程开发子分类