-1

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();
    }
}
maccettura
  • 10,514
  • 3
  • 28
  • 35
jbcom41
  • 57
  • 1
  • 6
  • 2
    That's the IPv6 address for localhost –  Apr 26 '18 at 15:06
  • 4
    Possible duplicate of [Request.UserHostAddress issue with return result "::1"](https://stackoverflow.com/questions/6408957/request-userhostaddress-issue-with-return-result-1) – Jamie Pollard Apr 26 '18 at 15:09

2 Answers2

0

Yes, this is an IPv6 address.

Try accessing the server using the IPv4 address (e.g. 127.0.0.1).

Max Malysh
  • 29,384
  • 19
  • 111
  • 115
0

You won't get the IP address if you are running from Visual Studio. You can deploy it to IIS then try it from a client to see the client's IP address. If the server has IPv4 enable, you will get the IPv4 address.

Brandon168
  • 21
  • 1
  • 8