C # Domain Name query
Last Update:2017-02-28
Source: Internet
Author: User
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>
<title></title>
<body>
<form runat= "Server" >
Domain Name: <asp:textbox id= "Txtdomain" value= "aspheute.com" runat= "Server"/>
<asp:button id= "Btnquery" onclick= "Doquery" text= "query!" runat= "Server"/>
<br><asp:label id= "Txtresult" runat= "Server"/>
</form>
</body>