以下内容介绍下java获取ip地址的几种思路. 1.直接利用java.net.InetAddress类获取,不过这种方法只在windows环境下有效,在linux环境下只能获取localhost地址(即/etc/hosts文件内容) 代码如下: import java.net.InetAddress; /** * This method works well in windows system. * In Linux system it returns 127.0.0.1 the content
方法1 public static String getIp2(HttpServletRequest request) { String ip = request.getHeader("X-Forwarded-For"); if (ip != null && !"unKnown".equalsIgnoreCase(ip)) { // 多次反向代理后会有多个ip值,第一个ip才是真实ip int index = ip.indexOf(",&q
[From] https://www.cnblogs.com/xiaoBlog2016/p/7076230.html 论述: 此篇博客是在工作的时候,需要获得当前网络下面正确的ip地址,在网上查阅很多博客,网上一个比较普遍的说法是通过InetAddress.getLocalHost().getHostAddress()获取,但只能够获取简单网络环境下的Ip地址,则忽略IP地址在现在的网络环境更加复杂,比如有Lan,WIFI,蓝牙热点,虚拟机网卡...即存在很多的网络接口(network inte