Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine Client's Computer Name

Tags:

c#

asp.net-mvc

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?

like image 656
Jimmy Avatar asked Sep 18 '09 13:09

Jimmy


People also ask

How do I find my client computer name?

In order to retrieve the client's computer name, you will have to query the DNS server with the client's IP. The IP can be easily retrieved by using the ASP.NET Request object with its UserHostAddress property.

How can you find out someone's name from their computer?

From the command line Type cmd /k hostname into the start menu and hit Enter . Your computer name will be displayed in the first line of a command prompt window. Alternatively, you can open any command prompt and enter hostname .


5 Answers

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();
}
like image 109
Jimmy Avatar answered Oct 17 '22 21:10

Jimmy


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)
like image 33
hosein kardoost Avatar answered Oct 17 '22 20:10

hosein kardoost


No. The client's computer name is not available in any way on the server. This is the nature of the http request-response. You only can have its IP address.

A workarounds could be to retrieve machine on the client from Flash/Silverlight (I doubt JavaScript) and put in into cookie which is available on the server with each request. But there is a whole stack of issues with this approach.

like image 28
Dmytrii Nagirniak Avatar answered Oct 17 '22 20:10

Dmytrii Nagirniak


I think you are better off using one of these methods to tie a user to a location:

  • a cookie that is set once the user self-selects their location
  • having the user login to the site so that you can track them uniquely that way
  • remembering user by IP address

There is no way of ensuring remote hostnames are unique. The same issue occurs with IP because of proxies, dynamic IP, etc., but I think it will be a little more reliable. Also, you can do geolocation by IP address.

like image 24
D'Arcy Rittich Avatar answered Oct 17 '22 19:10

D'Arcy Rittich


Try this:

string name = Request.UserHostName;
like image 42
Matt Wrock Avatar answered Oct 17 '22 21:10

Matt Wrock