Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I wrote a simple ASP.NET form that allows users to send me their needs. I have to retrieve their information like IP Address and their local computers' names. The codes that I wrote returns their correct IP Address. I don't have any problems with that. However, when I trying to retrive the computer name, it always returns the computer name that the actual application stays. In this case, my host server, webserver.

How can I retrieve their computer names? Is this possible?

PS: Client computers that send data using my asp form and server that holds the form are in the same network.

Here are the codes that I have been trying:

C#
string name1 = Environment.MachineName; //returns webserver
string name2 = System.Net.Dns.GetHostName(); //returns webserver
string name3 = System.Windows.Forms.SystemInformation.ComputerName; //returns webserver
string name4 = System.Environment.GetEnvironmentVariable("COMPUTERNAME").ToString();//returns webserver
Posted
Comments
JoCodes 16-Apr-15 12:39pm    
try Request.UserHostName
fatihkaratay 16-Apr-15 12:47pm    
Request.UserHostName and UserHostAddress return IP address of the user.
Sergey Alexandrovich Kryukov 16-Apr-15 13:02pm    
This is usually all what you can get about the computer. Why would it volunteer to give you a computer name?
The HTTP requests send by regular browsers won't to it. And the knowing of the computer name does not give you access to it anyway.
—SA
fatihkaratay 17-Apr-15 10:53am    
I understand your point. However, as I wrote before, clients and servers are in the same network.
Sergey Alexandrovich Kryukov 17-Apr-15 12:51pm    
Oh, then you can do it, depending on how clients participates in this network.

Only this is not related to your HTTP request. Roughly speaking, you can do these things separately: do the local network discovery and remember the data with the computer IP addresses. Then take the IP address from your HTTP request and then match with the data on the local network computers found at the moment.

—SA

1 solution

I'd suggest to read this: Back to Basics – Get Client Computer Name in ASP.NET[^]

[EDIT]

To get ip address of client computer in LAN:
How to retervie IP Address of machine on LAN[^] - mudassarkhan's answer.
 
Share this answer
 
v3
Comments
fatihkaratay 17-Apr-15 10:54am    
It worked. Thanks for the article. This time, I am having socket exception with some of the computers for some reasons. But mostly, I retrieved clients' computer names.
Maciej Los 17-Apr-15 11:20am    
You're very welcome ;)
Sergey Alexandrovich Kryukov 17-Apr-15 12:53pm    
Maciej,

Practically, this is not enough, by the reason we discussed. But later, the inquirer explained that the client are on the local network. Please see out discussion in the comments to the question and my suggestion. If you could provide the inquirer with the links on local network discovery, it could really solve the problem based on this suggestion. Will you?

—SA
Maciej Los 18-Apr-15 17:46pm    
Done ;)
Sergey Alexandrovich Kryukov 18-Apr-15 18:44pm    
5ed, thank you.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900