J. Petersen J. Petersen - 1 month ago 4
C# Question

Give user's IP for me - Right now it gives me only 127.0.0.1

This is how I would like to know what some IP addresses coming in to the website.

Therefore, I would like to get their IP address when possible.

Problem is that I now only get it here:

127.0.0.1.


The problem is that it happens when the content of the code is located on a server, so give it to me only the information with the IP address. I need the computer's IP or network. it does not matter. I just need the opportunity to Mazes person from the website.

The code that I use to showcase one's ips address it is this:

Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();

Answer

I use this:

Request.Params["HTTP_X_FORWARDED_FOR"] ?? Request.UserHostAddress

The first one gives you the IP if the user is behind a proxy. If it's null, then the second one will give you the right IP.

There are plenty of answered questions about this already. For example:

Getting the client IP address: REMOTE_ADDR, HTTP_X_FORWARDED_FOR, what else could be useful?