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
.NET Public-Key (Asymmetric) Cryptography DemoJuly 20, 2025
Raspberry Pi 3B+ Photo FrameJune 17, 2025
EBTCalc (Android) Version 1.53 is now availableMay 19, 2024
Vault 3 Security EnhancementsOctober 24, 2023
Vault 3 is now available for Apple OSX M2 Mac Computers!September 18, 2023
Vault (for Desktop) Version 0.77 ReleasedMarch 26, 2023
EBTCalc (Android) Version 1.44 is now availableOctober 12, 2021