469,319 Members | 2,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Making a domain lookup in asp.net

Hi!

I have found a script to lookup domain names, but it is written in C#. I
want so bad to translate this to VB! Can anyone help me? I have tried
myself. The script seems to run fine, but I never get any response on the
whois-information..

Really hope somone can help me with this.

Best regard,
Christopher Brandsdal

Here are the C# script followed by the one I tried to write in VB:

----------------
-- C# --
----------------

<% @Page Language="C#" Debug="false"%>
<% @Import Namespace="System.Net.Sockets" %>
<% @Import Namespace="System.Text" %>
<% @Import Namespace="System.IO" %>
<% @Import Namespace="System.Text.RegularExpressions" %>

<script language="C#" runat=server>

public void btn_Click(object sender, EventArgs eArgs)
{
try
{
TcpClient objTCPC = new TcpClient(Request.Form["WhoisServer"], 43);
string strDomain = Request.Form["DomainName"] + "\r\n";
byte[] arrDomain = Encoding.ASCII.GetBytes(strDomain);

Stream objStream = objTCPC.GetStream();
objStream.Write(arrDomain, 0, strDomain.Length);
StreamReader objSR = new StreamReader(objTCPC.GetStream(),
Encoding.ASCII);
lblResponse.Text = "<b>" + Request.Form["DomainName"] +
"</b><br><br>" + Regex.Replace(objSR.ReadToEnd(),"\n","<br>");

objTCPC.Close();
}
catch(Exception ex)
{
lblResponse.Text = ex.ToString();
}
}

</script>
<html>
<head>
<style>
..main {font-family:Verdana; font-size:12px;}
..title {font-family:Verdana; font-size:18px; font-weight:bold;}
</style>
</head>
<body>
<span class="title" align="center">WHOIS ASP.NET page</span>

<form id="Form1" method="POST" name="MainForm" runat="server">
<table>
<tr>
<td class="main" align="right">Whois Server</td>
<td class="main">
<asp:DropDownList class="main" id="WhoisServer" runat="server">
<asp:ListItem value="whois.networksolutions.com">
whois.networksolutions.com (.COM, .NET, .EDU)</asp:ListItem>
<asp:ListItem value="whois.ripe.net">whois.ripe.net
(Europe)</asp:ListItem>
<asp:ListItem value="whois.norid.no">whois.norid.no (.NO)
</asp:ListItem>
<asp:ListItem value="whois.nic.uk">whois.nic.uk
(.CO.UK)</asp:ListItem>
<asp:ListItem value="whois.domain-registry.nl">
whois.domain-registry.nl (.NL)</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="main" align="right">Domain Name:</td>
<td class="main"><input type="text" class="main"
name="DomainName" value=""></td>
</tr>
<tr>
<td class="main">&nbsp;</td>
<td class="main"><input type="Submit" id="btnSubmit"
OnServerClick="btn_Click" value="Send" runat="server" /></td>
</tr>
</table>
<br><br>
<asp:Label class="main" id="lblResponse" runat="server"/>
</form>
</body>
</html>


----------------
-- VB --
----------------

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<% @Import Namespace="System.Net.Sockets" %>
<% @Import Namespace="System.Text" %>
<% @Import Namespace="System.IO" %>
<% @Import Namespace="System.Text.RegularExpressions" %>

<script runat="server">
Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

dim objTCPC as TcpClient
dim strDomain as string
dim arrDomain as byte()
dim objStream as Stream
dim objSR as StreamReader

try
objTCPC = new TcpClient(Request.Form("WhoisServer"), 43)
strDomain = Request.Form("DomainName") & "\r\n"
arrDomain = Encoding.ASCII.GetBytes(strDomain)

objStream = objTCPC.GetStream()
objStream.Write(arrDomain, 0, strDomain.Length)
objSR = new StreamReader(objTCPC.GetStream(),Encoding.ASCII)
lblResponse.Text = "<b>" & Request.Form("DomainName") &
"</b><br><br>" & Regex.Replace(objSR.ReadToEnd(),"\n","<br>")

objTCPC.Close()
catch ex as Exception
lblResponse.Text = "Error!"
end try

End Sub
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<span class="title" align="center">WHOIS ASP.NET page</span>

<form id="Form2" method="POST" name="MainForm" runat="server">
<table>
<tr>
<td class="main" align="right">Whois Server</td>
<td class="main">
<asp:DropDownList id="WhoisServer" runat="server">
<asp:ListItem value="whois.networksolutions.com">
whois.networksolutions.com (.COM, .NET, .EDU)</asp:ListItem>
<asp:ListItem value="whois.ripe.net">whois.ripe.net
(Europe)</asp:ListItem>
<asp:ListItem value="whois.norid.no">whois.norid.no (.NO)
</asp:ListItem>
<asp:ListItem value="whois.nic.uk">whois.nic.uk
(.CO.UK)</asp:ListItem>
<asp:ListItem value="whois.domain-registry.nl">
whois.domain-registry.nl (.NL)</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="main" align="right">Domain Name:</td>
<td class="main"><input type="text" class="main"
name="DomainName" value=""></td>
</tr>
<tr>
<td class="main">&nbsp;</td>
<td class="main"><input type="Submit" id="btnSubmit"
OnServerClick="btn_Click" value="Send" runat="server" /></td>
</tr>
</table>
<br><br>
<asp:Label id="lblResponse" runat="server"/>
</form>
</body>
</html>
Aug 9 '06 #1
2 3928
"Christopher Brandsdal" <br*******@binaer.nowrote in
news:OJ**************@TK2MSFTNGP05.phx.gbl:
Hi!

I have found a script to lookup domain names, but it is written in C#.
I want so bad to translate this to VB! Can anyone help me? I have
tried myself. The script seems to run fine, but I never get any
response on the whois-information..

A lot of whois servers block external queries... not even sure if you can
query them directly anymore :(

Aug 9 '06 #2
When I use the C# code, it works fine! I just need to figure out how to
convert it to VB :-)
"Spam Catcher" <sp**********@rogers.comskrev i melding
news:Xn**********************************@127.0.0. 1...
"Christopher Brandsdal" <br*******@binaer.nowrote in
news:OJ**************@TK2MSFTNGP05.phx.gbl:
>Hi!

I have found a script to lookup domain names, but it is written in C#.
I want so bad to translate this to VB! Can anyone help me? I have
tried myself. The script seems to run fine, but I never get any
response on the whois-information..


A lot of whois servers block external queries... not even sure if you can
query them directly anymore :(

Aug 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Michael | last post: by
4 posts views Thread by JB | last post: by
2 posts views Thread by Tuncer Erhamza | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.