So here is the code and I'll explain what it does: I start a whois command line program and it checks a domain in this same class. Depending no whether or not the data received contains "No whois information available." it will set a bool in the class to true or false. If it's true the domain is registered if not it's open. The problem I have is for some reason I don't like the feeling of this but as soon as the program detects no whois information found it uses the KillWhois() function which kills the process!!
For some reason this feels sloppy as I'd rather cancel the event or something but perhaps this is the best I can do for this situation in terms of speed. Note: The code generally DOES work fine for most domains (not always). Ideas, etc? Thanks guys
For some reason this feels sloppy as I'd rather cancel the event or something but perhaps this is the best I can do for this situation in terms of speed. Note: The code generally DOES work fine for most domains (not always). Ideas, etc? Thanks guys
private bool bIs_Domain_Whois_Available()
{
using (var whois = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "whois.exe",
Arguments = this.strDomain,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
})
{
whois.OutputDataReceived += new DataReceivedEventHandler(whois_OutputDataReceived);
whois.Start();
whois.BeginOutputReadLine();
whois.WaitForExit();
whois.OutputDataReceived -= new DataReceivedEventHandler(whois_OutputDataReceived);
}
return (this.bLastWhoisExists);
}
private void StopWhois()
{
Process[] p = Process.GetProcessesByName("whois.exe");
foreach (Process whois in p)
{ whois.Kill(); }
}
private void whois_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
string output = e.Data;
if (e.Data != null && e.Data != "")
{
if (output.Contains("No whois information found"))
{
this.bLastWhoisExists = false;
this.StopWhois();
return;
}
this.bLastWhoisExists = true;
}
}