-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();
J. Petersen
  • 43
  • 1
  • 8

1 Answers1

2

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?

Community
  • 1
  • 1
Andrew
  • 7,602
  • 2
  • 34
  • 42
  • Note that X_FORWARDED_FOR can a) Have multiple IP addresses if multiple conforming proxy servers routed the request; b) be missing one or all of the IP addresses of proxy servers that do not set/update that header. I estimate the header is properly set, when appropriate, 99% of the time for normal internet users and 0% of the time for people using proxies to avoid geolocation. – Eric J. Oct 19 '16 at 23:49
  • Thanks for help. I will just look at it and thank you very much for your help. I hope you will give me a +1 for questions and I wish you a great day !! – J. Petersen Oct 19 '16 at 23:49