获取客户端计算机的IP地址 [英] Get IP address of client computer

查看:80
本文介绍了获取客户端计算机的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取客户端计算机的IP地址.我已经编写了代码,但是它仅显示服务器的IP,而不显示客户端计算机的IP.请帮助.


字符串带= Request.ServerVariables ["REMOTE_ADDR"];

strip = System.Web.HttpContext.Current.Request.ServerVariables ["HTTP_X_FORWARDED_FOR"];
strip = System.Environment.MachineName.ToString();
Response.Write(strip);

How to get IP address of Client Computer . I have written the code but it showing the IP of server only and not of Client Computer. plz help.


string strip =Request.ServerVariables["REMOTE_ADDR"];

strip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
strip = System.Environment.MachineName.ToString();
Response.Write(strip );

推荐答案

这可能有帮助

System.Net.Dns.GetHostByName(Environment.MachineName).AddressList [0] +";
This may help

System.Net.Dns.GetHostByName(Environment.MachineName).AddressList[0] + "";




尝试以下代码

Hi,

Try with the below code

HttpRequest request = HttpContext.Current.Request;
string ipAddress = request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if (ipAddress == null || ipAddress.ToLower() == "unknown")
      ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"];

return ipAddress;



这可能会对您有所帮助.



This may help you.


尝试此

Try this

HttpContext.Current.Request.UserHostAddress


这篇关于获取客户端计算机的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆