WHOIS information

  • Thread starter Thread starter Roel
  • Start date Start date
R

Roel

Hi all,

I want to query WHOIS info from my ASP.NET app.

I'd like to query a specific domain (e.g. google.com) and for availability
(e.g. google.eu (available/taken), google.nl (available/taken)).

Anyone knows a (commercial) component that gets this job done?

Kind Regards,
Roel
 
Hi Mark,

This is exactly what I mean!
I've searched for code samples on the net for this and there are many
indeed... but I can't get only one of them to work properly. Could you point
out some good examples? Thanx.

Roel
 
This is exactly what I mean!
I've searched for code samples on the net for this and there are many
indeed... but I can't get only one of them to work properly. Could you
point out some good examples? Thanx.

You can use mine if you like:

using System.Net.Sockets;

string strDomain = String.Empty;
string strWhoIs = String.Empty;
string strResponse = String.Empty;

using (TcpClient objTcpClient = new TcpClient())
{
objTcpClient.Connect(strWhoIs, 43);
byte[] arrDomain = Encoding.ASCII.GetBytes(mstrDomain);
Stream objStream = objTcpClient.GetStream();
objStream.Write(arrDomain, 0, mstrDomain.Length);
StreamReader objSr = new StreamReader(objTcpClient.GetStream(),
Encoding.ASCII);
strResponse = objSr.ReadToEnd();
}

Then just interrogate the value of strResponse for the existence of either
the string "no match" or "not found" - if either of those strings exists in
strResponse, you haven't got a match, otherwise you have.

The value of strWhoIs will depend on the domain's suffix - I use the
following List<>:

com: whois.crsnic.net
net: whois.crsnic.net
org: whois.crsnic.net
edu: whois.crsnic.net
biz: whois.neulevel.biz
info: whois.afilias.info
name: whois.nic.name

For the country-specific domains (e.g. .co.uk, .co.ca, .co.de etc) you
prefix the country code with "whois.nic." I.e. for a UK domain, you would
use whois.nic.uk and for a Canadian domain you would use whois.nic.ca etc...

Also, if the domain is a .com or a .net, you should put the string "domain "
in front of it, otherwise you'll get all the nameservers too... :-)

Incidentally, whereas this code *does* work, it's quite old now, and
searches on .biz domains always seem to time out... If anyone has any better
code for this, I'd be grateful to see it.
 
Hi, Mark.

Here's what I wrote, which works well:

void EnterBtn_Click(Object Src, EventArgs E)
{
String DomainName = Message.Text ;
String server = servers.SelectedItem.Text ;
TcpClient tcpc = new TcpClient(server, 43);
NetworkStream stream = tcpc.GetStream();
StreamWriter writer = new StreamWriter(stream);
StreamReader reader = new StreamReader(stream);
writer.AutoFlush = true;
writer.WriteLine(DomainName);
String line;
while ((line=reader.ReadLine())!=null)
Response.Write(line + "<br>");
tcpc.Close();
}

Test it and see if it works any better (post back the results if you do).

re:
searches on .biz domains always seem to time out

I use whois.nic.biz ( which I think is an alias for whois.neulevel.biz )
and seldom get timeouts.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
Mark Rae said:
Roel said:
This is exactly what I mean!
I've searched for code samples on the net for this and there are many indeed... but I can't get
only one of them to work properly. Could you point out some good examples? Thanx.

You can use mine if you like:

using System.Net.Sockets;

string strDomain = String.Empty;
string strWhoIs = String.Empty;
string strResponse = String.Empty;

using (TcpClient objTcpClient = new TcpClient())
{
objTcpClient.Connect(strWhoIs, 43);
byte[] arrDomain = Encoding.ASCII.GetBytes(mstrDomain);
Stream objStream = objTcpClient.GetStream();
objStream.Write(arrDomain, 0, mstrDomain.Length);
StreamReader objSr = new StreamReader(objTcpClient.GetStream(), Encoding.ASCII);
strResponse = objSr.ReadToEnd();
}

Then just interrogate the value of strResponse for the existence of either the string "no match"
or "not found" - if either of those strings exists in strResponse, you haven't got a match,
otherwise you have.

The value of strWhoIs will depend on the domain's suffix - I use the following List<>:

com: whois.crsnic.net
net: whois.crsnic.net
org: whois.crsnic.net
edu: whois.crsnic.net
biz: whois.neulevel.biz
info: whois.afilias.info
name: whois.nic.name

For the country-specific domains (e.g. .co.uk, .co.ca, .co.de etc) you prefix the country code
with "whois.nic." I.e. for a UK domain, you would use whois.nic.uk and for a Canadian domain you
would use whois.nic.ca etc...

Also, if the domain is a .com or a .net, you should put the string "domain " in front of it,
otherwise you'll get all the nameservers too... :-)

Incidentally, whereas this code *does* work, it's quite old now, and searches on .biz domains
always seem to time out... If anyone has any better code for this, I'd be grateful to see it.
 
Here's what I wrote, which works well:

<snip>

Looks good.
Test it and see if it works any better (post back the results if you do).

I will do so this evening...
I use whois.nic.biz ( which I think is an alias for whois.neulevel.biz )
and seldom get timeouts.

Thanks - I'll modify my List<> accordingly.
 
Hello Mark,

Your example was very useful to me. Many thanks!

Kind Regards,
Roel


Mark Rae said:
This is exactly what I mean!
I've searched for code samples on the net for this and there are many
indeed... but I can't get only one of them to work properly. Could you
point out some good examples? Thanx.

You can use mine if you like:

using System.Net.Sockets;

string strDomain = String.Empty;
string strWhoIs = String.Empty;
string strResponse = String.Empty;

using (TcpClient objTcpClient = new TcpClient())
{
objTcpClient.Connect(strWhoIs, 43);
byte[] arrDomain = Encoding.ASCII.GetBytes(mstrDomain);
Stream objStream = objTcpClient.GetStream();
objStream.Write(arrDomain, 0, mstrDomain.Length);
StreamReader objSr = new StreamReader(objTcpClient.GetStream(),
Encoding.ASCII);
strResponse = objSr.ReadToEnd();
}

Then just interrogate the value of strResponse for the existence of either
the string "no match" or "not found" - if either of those strings exists
in strResponse, you haven't got a match, otherwise you have.

The value of strWhoIs will depend on the domain's suffix - I use the
following List<>:

com: whois.crsnic.net
net: whois.crsnic.net
org: whois.crsnic.net
edu: whois.crsnic.net
biz: whois.neulevel.biz
info: whois.afilias.info
name: whois.nic.name

For the country-specific domains (e.g. .co.uk, .co.ca, .co.de etc) you
prefix the country code with "whois.nic." I.e. for a UK domain, you would
use whois.nic.uk and for a Canadian domain you would use whois.nic.ca
etc...

Also, if the domain is a .com or a .net, you should put the string "domain
" in front of it, otherwise you'll get all the nameservers too... :-)

Incidentally, whereas this code *does* work, it's quite old now, and
searches on .biz domains always seem to time out... If anyone has any
better code for this, I'd be grateful to see it.
 
Test it and see if it works any better (post back the results if you do).

At first, your code was a little quicker, but after I modified my code to
read:

NetworkStream objStream = objTcpClient.GetStream();

instead of

Stream objStream = objTcpClient.GetStream();

there was no appreciable difference... It now returns the 16 domain suffixes
in between one and two seconds, which is good enough for me... :-)
I use whois.nic.biz ( which I think is an alias for whois.neulevel.biz )
and seldom get timeouts.

Yep - that's fixed the timeouts - thanks.
 
Good news...on both counts!

NetworkStream is a bit more efficient. Don't ask me why. :-)
All I know is that it was suggested to me by someone who knows a lot!

Thanks for posting the results.





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
Back
Top