|
@@ -1,14 +1,17 @@
|
1
|
1
|
package com.xxl.job.core.util;
|
2
|
2
|
|
3
|
|
-import org.slf4j.Logger;
|
4
|
|
-import org.slf4j.LoggerFactory;
|
5
|
|
-
|
|
3
|
+import java.net.Inet6Address;
|
6
|
4
|
import java.net.InetAddress;
|
7
|
5
|
import java.net.NetworkInterface;
|
|
6
|
+import java.net.SocketException;
|
8
|
7
|
import java.net.UnknownHostException;
|
|
8
|
+import java.util.ArrayList;
|
9
|
9
|
import java.util.Enumeration;
|
10
|
10
|
import java.util.regex.Pattern;
|
11
|
11
|
|
|
12
|
+import org.slf4j.Logger;
|
|
13
|
+import org.slf4j.LoggerFactory;
|
|
14
|
+
|
12
|
15
|
/**
|
13
|
16
|
* get ip
|
14
|
17
|
* @author xuxueli 2016-5-22 11:38:05
|
|
@@ -42,15 +45,6 @@ public class IpUtil {
|
42
|
45
|
* @return
|
43
|
46
|
*/
|
44
|
47
|
private static InetAddress getFirstValidAddress() {
|
45
|
|
- InetAddress localAddress = null;
|
46
|
|
- try {
|
47
|
|
- localAddress = InetAddress.getLocalHost();
|
48
|
|
- if (isValidAddress(localAddress)) {
|
49
|
|
- return localAddress;
|
50
|
|
- }
|
51
|
|
- } catch (Throwable e) {
|
52
|
|
- logger.error("Failed to retriving ip address, " + e.getMessage(), e);
|
53
|
|
- }
|
54
|
48
|
try {
|
55
|
49
|
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
56
|
50
|
if (interfaces != null) {
|
|
@@ -78,9 +72,22 @@ public class IpUtil {
|
78
|
72
|
} catch (Throwable e) {
|
79
|
73
|
logger.error("Failed to retriving ip address, " + e.getMessage(), e);
|
80
|
74
|
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+ InetAddress localAddress = null;
|
|
78
|
+ try {
|
|
79
|
+ localAddress = InetAddress.getLocalHost();
|
|
80
|
+ if (isValidAddress(localAddress)) {
|
|
81
|
+ return localAddress;
|
|
82
|
+ }
|
|
83
|
+ } catch (Throwable e) {
|
|
84
|
+ logger.error("Failed to retriving ip address, " + e.getMessage(), e);
|
|
85
|
+ }
|
|
86
|
+
|
81
|
87
|
logger.error("Could not get local host ip address, will use 127.0.0.1 instead.");
|
82
|
88
|
return localAddress;
|
83
|
89
|
}
|
|
90
|
+
|
84
|
91
|
|
85
|
92
|
/**
|
86
|
93
|
* get address
|