I am using the following code. While running in localhost it gives correctly the client machine name, but when i run it the development server, it is not giving the actual result. any idea?
This is an asp.net mvc application.
string clientMachineName;
clientMachineName =
(Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName);
Response.Write(clientMachineName);
I want the computer name or machine name of the client that is making request. The above code gives me an value '172.16.12.100'.
any help much appreciated.
You do realize that, what you are asking and how you are doing is just wrong right?
You need to understand what's an IP Address in the first place.
When using Request.ServerVariables("REMOTE_ADDR")
this would never be the "real address",
since no "real address" is ever sent.
An IP address is something used at the network layer, and shouldn't really be used by your application, if you really want the identity of a given machine, you need to use something like X.509 certificates, which are meant to represent an identity (an IP address is not an identity).
You will have problems when a user is behind a NAT, and you will never get the correct identity of an user.
That is why under localhost everything works fine but soon you want something outside your "box" everything starts to go bad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With