Trying to capture the IP address of users within local network, but for some reason getting the following output on the web page "Your IP address is :::1"
is this IP6 address?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void getIP()
{
string IPaddr = string.Empty;
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDER_FOR"] != null)
{
IPaddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDER_FOR"].ToString();
}
else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
{
IPaddr = HttpContext.Current.Request.UserHostAddress;
}
Label1.Text = "Your IP address is :" + IPaddr;
}
protected void Page_Load(object sender, EventArgs e)
{
getIP();
}
}