惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - 末世纪狂潮

[导入]Pylogs v1.14beta (正式支持Django 1.0) 发布 [导入]Django中动态改变ImageField和FileField中文件的上传路径 [导入]Tech·ED 2008 票到了。。。 [导入]Windows Live Mail不能启动的解决办法 - 末世纪狂潮 [导入]Linux Mint中文语言包 [导入]XPS 1530安装MAC OsX 10.5.2指南 [导入]奥运加油,中国加油 [导入]IE7打不开微软的首页了? [导入]linux下常用格式的压缩与解压方法 [导入]利用PIL生成水印图片或文字 [导入]Pylogs v1.12beta发布 test live write write blog 用C#写一个简单的WINDOWS服务程序 测试tb .NET中实现无刷新客户端联动下拉菜单 "百万首页"深度思考 QQ天气预报代码 QQ登录没反应解决方法,及新版QQ的一个BUG 要开始学JAVA了,郁闷中。。。
[导入]ASP.NET获取客户端IP地址的几点补充[转载] - 末世纪狂潮 - 博客园
末世纪狂潮 · 2008-09-25 · via 博客园 - 末世纪狂潮

通常我们都通过下面的代码获得IP:
   string ip =System.Web.HttpContext.Current.Request.UserHostAddress;
    或 string ip =System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

REMOTE_ADDR 说明:

访问客户端的 IP 地址。
此项信息用户不可以修改。
如果真的给改了的话,你也和服务器连接不了了,服务器就是按照这个来与客户端建立连接并进行通讯的。实际我测试修改这个 ServerVariables , 一点效果都没有。仍然获得是实际的值。

但如果用户使用了代理服务器,上述代码获得的是代理服务器的IP地址;如果用户使用了多个代理服务器,则是到达服务器的最后一个代理服务器的IP地址。

如何绕过代理服务器获得用户真实的IP地址呢?

    
private
static string getIp()
 
     if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)   
      return System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0];      
    else
  
      return System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; 
 }

Request.ServerVariables["HTTP_VIA"] ,ServerVariables["HTTP_X_FORWARDED_FOR"],Request.ServerVariables["REMOTE_ADDR"]的值分下面几种情况:

一、没有使用代理服务器的情况:

      REMOTE_ADDR = 用户的 IP
      HTTP_VIA = 没数值或不显示
      HTTP_X_FORWARDED_FOR = 没数值或不显示

二、使用透明代理服务器的情况:Transparent Proxies

      REMOTE_ADDR = 最后一个代理服务器 IP
      HTTP_VIA = 代理服务器 IP
      HTTP_X_FORWARDED_FOR ...

文章来源:http://oteam.cn/2008/9/25/aspdotnet-get-client-ip-address/