ASP.NET pregunta con respecto a obtener la dirección IP de un usuario
-
02-10-2019 - |
Pregunta
Estoy tratando de buscar la dirección IP utilizando la siguiente: -
protected void Page_Load(object sender, EventArgs e)
{
string ClientIP;
ClientIP = HttpContext.Current.Request.UserHostAddress;
Label1.Text = ClientIP;
}
Este código salidas 127.0.0.1.
Y el código de abajo muestra nada!
string ClientIP;
ClientIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
Label1.Text = ClientIP;
¿Cómo voy a buscar la dirección IP? La dirección IP real de un usuario?
[EDIT]
No quiero ubicación exacta cierto. Necesito saber el país y luego redirigir al usuario a una página web en consecuencia.
Solución
Request.Params["REMOTE_ADDR"]
Otros consejos
El uso de System.Net, probar este -
// Then using host name, get the IP address list..
IPHostEntry ipEntry = DNS.GetHostByName (strHostName);
IPAddress [] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine ("IP Address {0}: {1} ", i, addr[i].ToString ());
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow