Checking whether a domain is unavailable and, if so, who owns it

M

Mark Rae

Hi,

For years I've been using the clwhois.exe app to check whether domains are
available or not and, if not, who owns them:

http://www.whoisview.com/products/clwhois/

Because this is a command line utility, it requires the
System.Diagnostics.Process class. It works well enough (code is below), but
I was wondering if anyone has a more efficient method. I'm aware that it's
possible to do a "basic" check with TCP Sockets, but that doesn't return
much registration information, so there didn't seem much point in having two
methods...

I suppose a free webservice would be the ideal solution...

Any assistance gratefully received.

Mark


using System;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

private string GetDomainInfo(string pstrDomain, string pstrSuffix)
{
/// <summary>
/// GetDomainInfo
/// </summary>
/// <param name="pstrDomain">Domain</param>
/// <param name="pstrSuffix">Suffix</param>
/// <returns>Response from whois server</returns>

Process objProcess = null;
bool blnFinished = false;

try
{
mstrDomain = pstrDomain + "." + pstrSuffix + "\r\n";

objProcess = new Process();
objProcess.StartInfo.UseShellExecute = false;
objProcess.StartInfo.RedirectStandardOutput = true;
objProcess.StartInfo.RedirectStandardError = true;
objProcess.StartInfo.CreateNoWindow = true;
objProcess.StartInfo.FileName =
Request.ServerVariables["APPL_PHYSICAL_PATH"] + "bin\\clwhois.exe";
objProcess.StartInfo.Arguments = "-d " + mstrDomain;
objProcess.StartInfo.WorkingDirectory =
Request.ServerVariables["APPL_PHYSICAL_PATH"] + "bin";
objProcess.Start();
blnFinished = objProcess.WaitForExit(10000);
if(blnFinished == false)
{
objProcess.Kill();
mstrResponse = "Server timed out";
}
else
{
mstrResponse = objProcess.StandardOutput.ReadToEnd();
mstrResponse = mstrResponse.Replace("Command Line Whois Version 1.01",
"");
mstrResponse = mstrResponse.Replace("Copyright (C) 2003 Softnik
Technologies", "");
mstrResponse = mstrResponse.Replace("Whois View -
http://www.whoisview.com", "");
mstrResponse = mstrResponse.Trim();
}
objProcess.Close();
objProcess.Dispose();
objProcess = null;

mstrResponse = mstrResponse.Replace("Error: Invalid characters in request
(only ASCII are allowed)\r\r\n", String.Empty);
mstrResponse = Regex.Replace(mstrResponse, "\r\n", "<br>");
mstrResponse = mstrResponse.Trim(new char[] {'<','b','r','>'});
return mstrResponse.Trim();
}
catch (Exception ex)
{
CApplication.GlobalExceptionHandler(ex);
return "No match";
}
finally
{
if (objProcess != null)
{
objProcess.Close();
objProcess.Dispose();
objProcess = null;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top