使用C#的客户端IP
如何在 C# 中获取客户端计算机的 IP 地址? 我想为我的在线应用程序保留一个日志寄存器,并保留日志系统的IP地址,我想获取客户端的IP地址......
提前谢谢......
How can i get IP address of client machine in C#.?
I want to keep a log register for my online application and to keep IP address of logging system i want to get the IP address of client....
Advance Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不试图考虑代理。为此,您可以使用
Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
。但是,请确保您不会盲目相信它,因为它可能是伪造的。最好保留一份您信任的 IP 白名单。This doesn't attempt to take into account proxies. For that, you can use
Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
. However, make sure you're not trusting that blindly, since it could be forged. It's better to keep a whitelist of IPs for which you trust it.