Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get IP Address?

Tags:

c#

.net

asp.net

I want to get the ip address whoever is registering in my site. How to do this in ASPNET. I used the following code, but, it is not getting the proper IP Address

string ipaddress = Request.UserHostAddress; 
like image 594
Developer404 Avatar asked Dec 15 '09 12:12

Developer404


People also ask

How do you find a IP address?

On an Android/tabletGo to your Wifi network settings, then select the network you're connected to. You'll find your IP address along with the other network information.

How easy is it to find an IP address?

How Easy Is It to Trace an IP Address? Tracing an unprotected IP address is as simple as a single line in the command prompt. However, if someone has hidden or obscured their IP with a decent VPN service, you'll just receive an error and get no information.


1 Answers

You can use this method to get the IP address of the client machine.

public static String GetIP() {     String ip =          HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];      if (string.IsNullOrEmpty(ip))     {         ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];     }      return ip; } 
like image 112
Muhammad Akhtar Avatar answered Oct 04 '22 02:10

Muhammad Akhtar