2

I'm having a scenario wherein I need either the machine name of the client who is accessing my website or his actual IP address.

I did a lot of searching and browsing and I found that most of the responses suggested me to use Request.ServerVariables["REMOTE_ADDR"] or Request.UserHostAddress. But this is not what I'm looking for. Both of these are returning the server's IP address instead of the actual IP address of the client who is accessing my website.

I found this particular article that shows how to get the IP address of the client using some external web service call. I tried it but it didn't work.

I even found many responses saying that getting the actual IP address isn't possible and getting the machine name of the client is also not possible if the client is accessing from outside the intranet.

Can someone please confirm this and correct me if I'm wrong? Thank you. :)

Amogh Natu
  • 781
  • 1
  • 10
  • 37
  • 2
    possible duplicate of [How to get a user's client IP address in ASP.NET?](http://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net) – Oliver Charlesworth Aug 02 '13 at 07:36
  • @OliCharlesworth Yeah it is indeed the same question. In that post, the responses say that I can't get the IP address. But I have found other answers too that are contradicting. So I just want to confirm the same. Can you please tell me whether I can get the IP address/Machine name of the client or I cannot? Thank you. – Amogh Natu Aug 02 '13 at 08:39
  • Possible duplicate of [How to get client's IP address using javascript only?](http://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript-only) – mido Jan 23 '17 at 12:37

3 Answers3

4

try this site

http://www.geekpedia.com/tutorial45_How-to-get-IP-address-of-client.html

here they have given a way to do it may be it will help

Alok Agarwal
  • 3,071
  • 3
  • 23
  • 33
  • It is again asking me to use Request.ServerVariables["REMOTE_ADDR"]. But I'm not getting the IP address that I should be getting if I use this. – Amogh Natu Aug 02 '13 at 08:41
  • It worked. I was checking everything in my local machine so I was getting a different IP. When I deployed the code in a remote server and tried accessing from my local machine, I got the IP address that was expected. Thanks a lot! :-) – Amogh Natu Sep 16 '13 at 12:30
3

You can't get the IP if the machine is behind a proxy. What's your exact use case?

Devendra Bhatte
  • 358
  • 4
  • 18
2

Are you using a proxy or reverse-proxy of some kind? REMOTE_ADDR should indeed be the client source ip.