Question

Determine Client's Computer Name

I am building an intranet site that will display different lists based on the computer name because different computers are in different areas, is there a way (within a controller or model) to determine the client's computer name?

I have tried system.environment.machinename but that only returns the name of the server, any other ideas?

 45  74591  45
1 Jan 1970

Solution

 54

I got it working using the following:

string IP = Request.UserHostName;
string compName = CompNameHelper.DetermineCompName(IP);

code from compnamehelper:

public static string DetermineCompName(string IP)
{
    IPAddress myIP = IPAddress.Parse(IP);
    IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
    List<string> compName = GetIPHost.HostName.ToString().Split('.').ToList();
    return compName.First();
}
2009-09-18

Solution

 4

code in VB :

Dim myIP As IPAddress = IPAddress.Parse(Request.UserHostName)
    Dim GetIPHost As IPHostEntry = Dns.GetHostEntry(myIP)
    Dim compName As List(Of String) = GetIPHost.HostName.ToString.Split("").ToList

    return(compName.First)
2014-10-16