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.