Get Client IP Address in ASP.NET using JavaScript
So, it all started with a requirement for my website when I needed to get the client's IP address for some security purposes. It felt like an easy task initially, but after some time, I realized that most of the available methods of getting an IP address return the Server's IP Address and not the local IP address of the client. And some APIs return your Public IP address, but none return the local IP address. So, we will see how we can achieve that.
Using JavaScript
In JavaScript, you can use the following script to get the IP address.
Just paste this script into your JavaScript code and add this element to your body tag.
Now, just run the code, and this will get you your Client or Local IP address.
Getting Public IP address
There are two types of IP addresses - Local and Public. The above script is for getting the Client or Local IP Address, but for getting the Public IP Address, you can use this script.
This will return your Public IP Address.