Eric Bergman-Terrell's Blog

Ruby on Rails Versus ASP.NET MVC: WHOIS
November 22, 2011

As of yesterday, this site is hosted by a new hosting provider (site5). Previously, the website was written in ASP.NET MVC2, running on Windows, using MS SQL Server. It now runs on Linux, using the MySQL database. Please report any website issues to me.

I didn't re-engineer the website because of any flaws in the previous environment. I just wanted to "kick the tires" on Rails, and see what all the fuss is about. So far it's been a lot of fun!

My website includes a WHOIS utility. WHOIS is a mechanism to look up domain registration information.

The following is the Ruby and .NET WHOIS code. Note, the Ruby implementation is very basic. For instance, it relies on whatever default timeouts are in effect.

Ruby WHOIS Code:

class WHOIS

...

  def WHOISText
    socket = TCPSocket.open(Rails.configuration.WHOIS_host, 43)

    socket.write @domain + "\r\n"

    lines = ""

    while line = socket.gets
      lines += line
    end

    socket.close

    lines
  end

...

end

.NET WHOIS Code:

namespace EricBT
{
    public static class WHOIS
    {
        // http://www.aspdev.org/articles/build-whois-lookup-asp.net/
        public static string GetWHOISText(string domain)
        {
            Globals.Log.InfoFormat("WHOIS.GetWHOISText: domain: {0}", domain);

            string serverResponse = null;

            try
            {
                string whoisServer = ConfigurationManager.AppSettings["WHOISServer"];

                using (TcpClient objTCPC = new TcpClient())
                {
                    objTCPC.SendTimeout = Convert.ToInt32(ConfigurationManager.AppSettings["WHOISSendTimeout"]);
                    objTCPC.ReceiveTimeout = Convert.ToInt32(ConfigurationManager.AppSettings["WHOISReceiveTimeout"]);

                    objTCPC.Connect(whoisServer, 43);

                    string strDomain = string.Format("{0}\r\n", domain);

                    byte[] arrDomain = Encoding.ASCII.GetBytes(strDomain);

                    using (Stream objStream = objTCPC.GetStream())
                    {
                        objStream.Write(arrDomain, 0, strDomain.Length);

                        using (StreamReader objSr = new StreamReader(objTCPC.GetStream(), Encoding.ASCII))
                        {
                            serverResponse = objSr.ReadToEnd().Trim();

                            Globals.Log.InfoFormat("WHOIS.GetWHOISText: Response: {0}", serverResponse);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.Log.ErrorFormat("WHOIS.GetWHOISText: Exception {0}", ex);

                serverResponse = string.Format("Error retrieving WHOIS information for domain '{0}'", domain);
            }

            return serverResponse;
        }
    }
}
Keywords: Ruby on Rails, ASP.NET MVC, WHOIS, MySQL, MS SQL Server, Windows, Linux

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
Java Programming Tip: SWT Photo Frame ProgramOctober 31, 2016
Vault 3 (Desktop) Version 1.63 ReleasedSeptember 9, 2016
"Compliance with Court Orders Act of 2016"April 9, 2016
Disable "Visual Voicemail" on Android / T-MobileJanuary 17, 2016
IPv6 HumorDecember 10, 2015
Java Programming Tip: Specify the JVM time zoneDecember 7, 2015
Node.js / Express Programming Tip: Detect and Fix Memory LeaksOctober 27, 2015