001  <% @Page Language="C#" %>
002  <% @Import Namespace="System.Net.Sockets" %>
003  <% @Import Namespace="System.Text" %>
004  <% @Import Namespace="System.IO" %>
005  <% @Import Namespace="System.Collections" %>
006  <script language="C#" runat="server">
007  void doQuery(Object sender, EventArgs e)
008  {
009   String strDomain = txtDomain.Text;
010   char[] chSplit = {'.'};
011   string[] arrDomain = strDomain.Split(chSplit);
012   // es darf genau ein domain name + ein suffix sein
013   if (arrDomain.Length != 2)
014   {
015   return;
016   }
017  
018   // das suffic darf nur 2 oder 3 zeichen lang sein
019   int nLength = arrDomain[1].Length;
020   if (nLength != 2 && nLength != 3)
021   {
022   return;
023   }
024  
025   Hashtable table = new Hashtable();
026   table.Add("at", "whois.nic.at");
027   table.Add("de", "whois.denic.de");
028   table.Add("be", "whois.dns.be");
029   table.Add("gov", "whois.nic.gov");
030   table.Add("mil", "whois.nic.mil");
031  
032   String strServer = "whois.networksolutions.com";
033   if (table.ContainsKey(arrDomain[1]))
034   {
035   strServer = table[arrDomain[1]].ToString();
036   }
037   else if (nLength == 2)
038   {
039   // 2-letter TLD's always default to RIPE in Europe
040   strServer = "whois.ripe.net";
041   }
042  
043   String strResponse;
044   bool bSuccess = DoWhoisLookup(strDomain, strServer, out strResponse);
045   if (bSuccess)
046   {
047   txtResult.Text = strResponse;
048   }
049   else
050   {
051   txtResult.Text = "Lookup failed";
052   }
053  }
054  
055  bool DoWhoisLookup(String strDomain, String strServer, out String strResponse)
056  {
057   strResponse = "none";
058   bool bSuccess = false;
059  
060   TcpClient tcpc = new TcpClient();
061   try
062   {
063   tcpc.Connect(strServer, 43);
064   }
065   catch(SocketException ex)
066   {
067   strResponse = "Could not connect to Whois server";
068   return false;
069   }
070  
071   strDomain += "\r\n";
072   Byte[] arrDomain = Encoding.ASCII.GetBytes(strDomain.ToCharArray());
073   try
074   {
075   Stream s = tcpc.GetStream();
076   s.Write(arrDomain, 0, strDomain.Length);
077  
078   StreamReader sr = new StreamReader(tcpc.GetStream(), Encoding.ASCII);
079   StringBuilder strBuilder = new StringBuilder();
080   string strLine = null;
081  
082   while (null != (strLine = sr.ReadLine()))
083   {
084   strBuilder.Append(strLine+"<br>");
085   }
086   tcpc.Close();
087  
088   bSuccess = true;
089   strResponse = strBuilder.ToString();
090   }
091   catch(Exception e)
092   {
093   strResponse = e.ToString();
094   }
095  
096   return bSuccess;
097  }
098  </script>
099  <html>
100  <head>
101  <title></title>
102  </head>
103  <body>
104  
105  <form runat="server">
106  Domain name: <asp:TextBox id="txtDomain" value="aspheute.com" runat="server" />
107   <asp:Button id="btnQuery" OnClick="doQuery" text="Query!" runat="server" />
108  <BR><HR width="100%"><BR>
109  <asp:label id="txtResult" runat="server" />
110  </form>
111  
112  </body>
113  </html>
114