【发布时间】:2018-04-26 15:03:43
【问题描述】:
试图在本地网络中捕获用户的 IP 地址,但由于某种原因在网页上得到以下输出“您的 IP 地址是 :::1”
这是 IP6 地址吗?
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();
}
}
【问题讨论】:
-
这是 localhost 的 IPv6 地址
标签: c#