Thursday 6 January 2011

Who are you? Who are you?

One small problem that we have hit in the last couple of days is figuring out the hostname of the computer that is connecting to our web app. We need this information because we have a queueing system in our One Stop Shops that sends customers to a specific desk when next customer service officer is free.

All our efforts so far have failed because we have only been able to get the hostname of the server that the app is deployed on. There is a libary within the .NET framework that gives you this info and there are plenty of examples on forums that tell you how to extract the value - Environment.MachineName, DNS.GetHostName, Request.UserHostName are three examples that don't work.

One of my colleagues had the idea of doing a reverse DNS lookup so we gave that a shot. Microsoft themselves recommend that you start monkeying around with the settings on IIS but I don't want to do that because I have no idea what effects it may have down the line. Rich Czyzewski suggests a few lines of code in this blog post which we tried out. Unfortunately this failed - we could see the hostname of the server when we browsed to the web page on the server itself. But when we browsed to the web page from our desktops no hostname showed up, and there were no errors being reported through Try / Catch either.

A bit more reading suggested that we try looking at the Request.Server variables collection. This is an array of values that get passed through from the browser. While no hostname was included this does look like a reliable way of picking up the IP Address of the client which is a start. The majority of desktops that will be connecting to our app have dynamic IP addresses so we can't guarantee the same one every time and therefore can't build a lookup table. So I hit on the idea of trying to do something with PING - i.e. get the IP Address of the client and ping back to it to pick up the hostname. I know that if you run the command "ping -a 111.222.333.444" on the Windows command prompt you get a hostname back. So the next step is to try and figure out if I can do something similar from the web server without crashing the application.

No comments: