locked
How to get User Agent IP Address RRS feed

  • Question

  • User1239610449 posted

    I need to get every single user IP address when he logged in to the application.

    For which I am using the following:

    Request.UserHostAddress

    But it shows always ::1

    Please advise, how to get IP address.

    Wednesday, April 10, 2019 10:27 AM

Answers

  • User475983607 posted

    You mean to say that I should host the web page on IIS so that it will show the correct IP rather than to run on localhost.

    It has to be hosted on a remote system.  However, reading the IP in a web application is seldom the solution due to networking fundamentals.

    What problem are you trying to solve?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 10, 2019 12:09 PM

All replies

  • User753101303 posted

    Hi,

    This is the IP v6 loopback address so this is expected if running on localhost. You could also check first https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For if available and then only use UserHostAddress.

    Wednesday, April 10, 2019 10:46 AM
  • User1239610449 posted

    Thanks for reply

    You mean to say that I should host the web page on IIS so that it will show the correct IP rather than to run on localhost.

    Wednesday, April 10, 2019 11:47 AM
  • User475983607 posted

    You mean to say that I should host the web page on IIS so that it will show the correct IP rather than to run on localhost.

    It has to be hosted on a remote system.  However, reading the IP in a web application is seldom the solution due to networking fundamentals.

    What problem are you trying to solve?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 10, 2019 12:09 PM
  • User753101303 posted

    Yes. As most developers you are in the very special case where your browser and the web server are running on the same machine in which case you are using "localhost" (and its special 127.0.0.1 or ::1 address). It means basically "the same machine" so that the http request is sent from your browser to a web server on the same machine.

    As pointed by mgebhard you may want to explain your final goal. At best it could be "for information" but your application should not depend on this (for example a company could expose multiple machines using a single IP or if you have a box your IP address could change over time etc... so in particular it shouldn't be considered as a unique id).

    Wednesday, April 10, 2019 12:22 PM
  • User1239610449 posted

    My objective is that my application is hosted on remote system and the user of that application is using from different machine within the same IP pool. So, I want if the user has the same IP address which I have defined in the system for that user then user will be able to logged in.

    Monday, April 15, 2019 6:05 AM
  • User839733648 posted

    Hi knowledgist,

    As mgebhard and PatriceSc have mentioned, it is because you have run your application in local.

    Have you tried to run your application on another machine?

    In my opinion, if you visit your application from different machine, the IP address will be different and will all log in successfully.

    Best Regards,

    Jenifer

    Wednesday, April 17, 2019 6:09 AM
  • User753101303 posted

    Seems definitively your browser and the web server is on the same machine and so you get the "localhost" address. Try a real deployment.

    You could also have a look at https://www.ntweekly.com/2017/07/21/block-specific-ip-address-from-accessing-iis-10-web-site/  to configure restrictions at the IIS level.

    Wednesday, April 17, 2019 7:34 AM
  • User1052662409 posted

    I need to get every single user IP address when he logged in to the application.

    https://stackoverflow.com/questions/21155352/get-ip-address-of-client-machine

    Wednesday, April 17, 2019 10:20 AM