Determine Client's Computer Name

Determine Client's Computer Name

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();
}

How to get client's computer name

Two things to consider:

  1. Take into account that HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST") will return the name of the host making the request, not the address.
  2. Try doing System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST")).HostName instead.

You can find a list of the Server Variables at Microsoft's MSDN website.

Hope that helps,

How to get clients computer name using asp.net mvc?

No you can't, unless the client sends such info when making HTTP requests. By "client", I'm referring to any - some app, browser, etc.

You can inspect your own browser request flow using standard browser dev tools and see exactly what info your browser is sending. It will not have your machine name (unless something in your machine is and that would likely be a problem).

That said, HTTP Header data is what you have aside from standard network info such as IP address (which also isn't guaranteed to be the client's IP address - it could be the client's network address). The closest you can get to is hostname if it exists, and even then, just like IP address, is not guaranteed to be machine name.

A possible exception would be in an internal network (LAN).

How can I read the client's machine/computer name from the browser?

You can do it with IE 'sometimes' as I have done this for an internal application on an intranet which is IE only. Try the following:

function GetComputerName() {
try {
var network = new ActiveXObject('WScript.Network');
// Show a pop up if it works
alert(network.computerName);
}
catch (e) { }
}

It may or may not require some specific security setting setup in IE as well to allow the browser to access the ActiveX object.

Here is a link to some more info on WScript: More Information

How to get Client computer name from Asp.net web application (internet application)

You can get Computer names using codes if they are in a network(intranet) which works fine as you suggested.

At the same time when the system is accessed via internet there is no computer name rather Domain name.

I want to get the machine name of the client the request is being made
from. With ASP I can get the IP address. But I don’t know how to get
the name of the machine. Is there something I could do from the client
side?

No, the web browser client cannot determine the name of the machine.

Clients and servers should not trust each other. In the absence of
authentication evidence, clients must assume that all servers are run
by evil hackers and servers must assume that all clients are run by
evil hackers. Once you accept that fundamental design principle then
it becomes much easier to reason about client-server interactions.
Think like an evil person!

More reference on the topic (Retrieving the system name) , you can refer :

Stack Overflow posts :

  1. Get Client ip address and system name
  2. How get client (user) machine name (computer name) with jQuery or JavaScript or server-side codes.

Hope that will put more light on the issue.

How I can obtain client hostname, local computer name and user name in c# and asp.net

Use HttpRequest.UserHostAddress and HttpRequest.UserHostName for client IP and machine name.

Assuming you have authentication configured correctly, you can get the client user from IIdentity.Name.

In the context of a Page, you can use Request.UserHostAddress, Request.UserHostName and User.Identity.Name.



Related Topics



Leave a reply



Submit