You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/09/05 12:20:06 UTC

[GitHub] [inlong] healchow commented on a diff in pull request #5778: [INLONG-5770][DataProxy] Optimize the method of obtaining the local IP address

healchow commented on code in PR #5778:
URL: https://github.com/apache/inlong/pull/5778#discussion_r962847373


##########
inlong-common/src/main/java/org/apache/inlong/common/util/NetworkUtils.java:
##########
@@ -17,59 +17,55 @@
 
 package org.apache.inlong.common.util;
 
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.util.Enumeration;
 
 public class NetworkUtils {
-    public static String INNER_NETWORK_INTERFACE = "eth1";
 
-    private static String localIp = null;
+    private static final Logger LOGGER = LoggerFactory.getLogger(NetworkUtils.class);
+    private static String localIp;
 
     static {
         localIp = getLocalIp();
     }
 
     /**
      * get local ip
-     * @return
      */
     public static String getLocalIp() {
-        if (localIp == null) {
-            String ip = null;
-            Enumeration<NetworkInterface> allInterface;
-            try {
-                allInterface = NetworkInterface.getNetworkInterfaces();
-                for (; allInterface.hasMoreElements(); ) {
-                    NetworkInterface oneInterface = allInterface.nextElement();
-                    String interfaceName = oneInterface.getName();
-                    if (oneInterface.isLoopback()
-                            || !oneInterface.isUp()
-                            || !interfaceName
-                            .equalsIgnoreCase(INNER_NETWORK_INTERFACE)) {
-                        continue;
-                    }
+        if (!StringUtils.isEmpty(localIp)) {

Review Comment:
   Suggest using `StringUtils.isNotBlank()`.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org