@@ -38,28 +38,19 @@ public static boolean isNetWorkReady() {
3838 */
3939 public static String getHostIP () {
4040 String hostIp = null ;
41- String ipv6 = null ;
4241 try {
4342 Enumeration nis = NetworkInterface .getNetworkInterfaces ();
4443 InetAddress ia = null ;
4544 while (nis .hasMoreElements ()) {
4645 NetworkInterface ni = (NetworkInterface ) nis .nextElement ();
4746 Enumeration <InetAddress > ias = ni .getInetAddresses ();
48- while (ias .hasMoreElements ()) {
49- ia = ias .nextElement ();
50- if (ia instanceof Inet6Address ) {
51- //ipv6 = checkIpv6(ia.getHostAddress());
52- if (!ia .isLinkLocalAddress ()&&!ia .isLoopbackAddress ()) {
53- hostIp = ia .getHostAddress ();
54- break ;
55- }
56- continue ;
57- }
58- String ip = ia .getHostAddress ();
59- if (!"127.0.0.1" .equals (ip )) {
47+ ia = ias .nextElement ();
48+ if (ia instanceof Inet6Address ) {
49+ if (!ia .isLinkLocalAddress () && !ia .isLoopbackAddress ()) {
6050 hostIp = ia .getHostAddress ();
6151 break ;
6252 }
53+ continue ;
6354 }
6455 }
6556 } catch (SocketException e ) {
@@ -68,27 +59,4 @@ public static String getHostIP() {
6859 return hostIp ;
6960 }
7061
71- /**
72- * first segment contains "fe" or "fc": https://blog.csdn.net/fdl19881/article/details/7091138
73- *
74- * @param ipv6
75- * @return
76- */
77- private static String checkIpv6 (String ipv6 ) {
78- if (ipv6 != null ) {
79- String [] split = ipv6 .split ("%" );
80- String s1 = split [0 ];
81- if (s1 != null && s1 .contains (":" )) {
82- String [] split1 = s1 .split (":" );
83- if (split1 .length == 6 || split1 .length == 8 ) {
84- if (split1 [0 ].contains ("fe" ) || split1 [0 ].contains ("fc" )) {
85- return null ;
86- } else {
87- return s1 ;
88- }
89- }
90- }
91- }
92- return null ;
93- }
9462}
0 commit comments