How to get the computer name (hostname in a web aplication)?

Posted by Filipe on Stack Overflow See other posts from Stack Overflow or by Filipe
Published on 2010-05-17T16:02:25Z Indexed on 2010/05/17 16:30 UTC
Read the original article Hit count: 182

Filed under:

Hi, how can I get the client's computer name in a web application. The user in a network.

Regards

// Already tryed this option

string IP = System.Web.HttpContext.Current.Request.UserHostAddress;
string compName = DetermineCompName(IP);

System.Net.IPHostEntry teste = System.Net.Dns.GetHostEntry(IP);
ssresult = IP + "   -   " + teste.HostName;

// TODO: Write implementation for action

private static string DetermineCompName(string IP)
{
   IPAddress myIP = IPAddress.Parse(IP);
   IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
   string[] compName = GetIPHost.HostName.ToString().Split('.');
   return compName[0];
}

All of that, gives me only the IP :/

© Stack Overflow or respective owner

Related posts about c#