
private String getIpAddr() {
String ipAddress = null;
//ipAddress = thisgetRequest()getRemoteAddr();
ipAddress = thisgetRequest()getHeader("x-forwarded-for");
if(ipAddress == null || ipAddresslength() == 0 || "unknown"equalsIgnoreCase(ipAddress)) {
ipAddress = thisgetRequest()getHeader("Proxy-Client-IP");
}
if(ipAddress == null || ipAddresslength() == 0 || "unknown"equalsIgnoreCase(ipAddress)) {
ipAddress = thisgetRequest()getHeader("WL-Proxy-Client-IP");
}
if(ipAddress == null || ipAddresslength() == 0 || "unknown"equalsIgnoreCase(ipAddress)) {
ipAddress = thisgetRequest()getRemoteAddr();
if(ipAddressequals("127001")){
//根据网卡取本机配置的IP
InetAddress inet=null;
try {
inet = InetAddressgetLocalHost();
} catch (UnknownHostException e) {
eprintStackTrace();
}
ipAddress= inetgetHostAddress();
}
}
//对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if(ipAddress!=null && ipAddresslength()>15){ //""length() = 15
if(ipAddressindexOf(",")>0){
ipAddress = ipAddresssubstring(0,ipAddressindexOf(","));
}
}
return ipAddress;
}
我才用的一个项目,requestgetRemoteAddr();
不是很准确
1、在电脑桌面找到网络图标,右击选择属性。
2、进入属性之后,点击本地连接。
3、然后在跳出的窗口中找到属性并左击。如下图:
4、然后在跳出的窗口中找到“Internet协议版本4(TCP/IPV4)”,选中之后双击它。
5、然后按照下图在自动获得IP地址选项前面点击选择。
6之后按下面确定完成 *** 作。
大型项目中一般这样获取
/// <summary>
/// 获取客户端IP
/// </summary>
public static string ClientIP
{
get
{
string result = >
以上就是关于JAVA求教SSH项目中如何获取外来访问者的IP地址全部的内容,包括:JAVA求教SSH项目中如何获取外来访问者的IP地址、怎么把网络连接设置成自动获取IP、Asp.net如何获取客户端的IP等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)