request.getRemoteAddr怎么获取用户真实的IP地址

request.getRemoteAddr怎么获取用户真实的IP地址,第1张

请求客户端是不是用代理了如果用了代理就不能这么获取了

public

string

getipaddr(>

你的网卡设置中看看,一般情况下,你的网关就是你的代理服务器的ip地址,如果是自动获取的,在命令行中输入ipconfig

/all,可以看到你的网关ip

回答不容易,希望能帮到您,满意请帮忙采纳一下,谢谢

!

java获取外网ip地址方法:

public class Main {

public static void main(String[] args) throws SocketException {

Systemoutprintln(MaingetRealIp());

}

public static String getRealIp() throws SocketException {

String localip = null;// 本地IP,如果没有配置外网IP则返回它

String netip = null;// 外网IP

Enumeration<NetworkInterface> netInterfaces =

NetworkInterfacegetNetworkInterfaces();

InetAddress ip = null;

boolean finded = false;// 是否找到外网IP

while (netInterfaceshasMoreElements() && !finded) {

NetworkInterface ni = netInterfacesnextElement();

Enumeration<InetAddress> address = nigetInetAddresses();

while (addresshasMoreElements()) {

ip = addressnextElement();

if (!ipisSiteLocalAddress()

&& !ipisLoopbackAddress()

&& ipgetHostAddress()indexOf(":") == -1) {// 外网IP

netip = ipgetHostAddress();

finded = true;

break;

} else if (ipisSiteLocalAddress()

&& !ipisLoopbackAddress()

&& ipgetHostAddress()indexOf(":") == -1) {// 内网IP

localip = ipgetHostAddress();

}

}

}

if (netip != null && !""equals(netip)) {

return netip;

} else {

return localip;

}

}

}

以上就是关于request.getRemoteAddr怎么获取用户真实的IP地址全部的内容,包括:request.getRemoteAddr怎么获取用户真实的IP地址、在java后台服务器,如何根据HttpSession获得客户端ip、怎么查看自己的HTTP代理的IP地址等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9787313.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存