当您浏览网页(例如 whatismyip.com)时,您的计算机会将您的 IP 地址通知服务器,以便服务器可以将您请求的网页的 HTML、图形和其他元素发回给您。
考虑以下服务器变量(C# 代码):
string server = Request.ServerVariables["SERVER_NAME"];
string url = Request.ServerVariables["URL"];
querystring = Request.ServerVariables["QUERY_STRING"];
string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress == null || ipAddress == "")
{
ipAddress = Request.ServerVariables["REMOTE_ADDR"];
}
以下是其他一些变量:
"HTTP_X_COMING_FROM"
"HTTP_X_FORWARDED_FOR"
"HTTP_X_FORWARDED"
"HTTP_X_REAL_IP"
"HTTP_VIA"
"HTTP_COMING_FROM"
"HTTP_FORWARDED_FOR"
"HTTP_FORWARDED"
"HTTP_FROM"
"HTTP_PROXY_CONNECTION"
"CLIENT_IP"
"FORWARDED"