gosonzhang commented on a change in pull request #97:
URL: https://github.com/apache/incubator-tubemq/pull/97#discussion_r429904551
##########
File path:
tubemq-core/src/main/java/org/apache/tubemq/corebase/utils/AddressUtils.java
##########
@@ -130,4 +134,100 @@ public static String getRemoteAddressIP(Channel channel) {
}
return strRemoteIP;
}
+
+ public static String getLocalIPv4Address() {
+ List<String> ips = listNonLoopbackIPV4Address();
+
+ if (ips.isEmpty()) {
+ try {
+ return InetAddress.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ String errorMsg = "Unable to obtain local IP, please manually
specify the local IP address";
+ throw new AddressException(errorMsg, e.getCause());
+ }
+ }
+
+ for (String ip : ips) {
+ if (ip.startsWith("192.168")) {
+ continue;
+ }
+
+ return ip;
+ }
+
+ return ips.get(ips.size() - 1);
Review comment:
If ips is empty, how to do?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]