diff --git a/agent/java/src/main/java/com/fuxi/javaagent/HookHandler.java b/agent/java/src/main/java/com/fuxi/javaagent/HookHandler.java index 668fde118..d491ef93e 100755 --- a/agent/java/src/main/java/com/fuxi/javaagent/HookHandler.java +++ b/agent/java/src/main/java/com/fuxi/javaagent/HookHandler.java @@ -41,10 +41,7 @@ import com.fuxi.javaagent.request.AbstractRequest; import com.fuxi.javaagent.request.HttpServletRequest; import com.fuxi.javaagent.response.HttpServletResponse; -import com.fuxi.javaagent.tool.FileUtil; -import com.fuxi.javaagent.tool.Reflection; -import com.fuxi.javaagent.tool.StackTrace; -import com.fuxi.javaagent.tool.TimeUtils; +import com.fuxi.javaagent.tool.*; import com.fuxi.javaagent.tool.hook.CustomLockObject; import com.fuxi.javaagent.tool.security.SqlConnectionChecker; import com.fuxi.javaagent.tool.security.TomcatSecurityChecker; diff --git a/agent/java/src/main/java/com/fuxi/javaagent/tool/OSUtil.java b/agent/java/src/main/java/com/fuxi/javaagent/tool/OSUtil.java index 596b60b0c..ea5cb44bf 100644 --- a/agent/java/src/main/java/com/fuxi/javaagent/tool/OSUtil.java +++ b/agent/java/src/main/java/com/fuxi/javaagent/tool/OSUtil.java @@ -32,31 +32,27 @@ import com.fuxi.javaagent.tool.model.NicModel; -import java.net.*; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; import java.util.Enumeration; -import java.util.HashMap; import java.util.LinkedList; public class OSUtil { private static InetAddress inetAddress; - static { - try { - inetAddress = InetAddress.getLocalHost(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - } - public static String getHostName() { return inetAddress == null ? null : inetAddress.getHostName(); } public static LinkedList getIpAddress() { LinkedList ipList = new LinkedList(); - Enumeration allNetInterfaces = null; try { + if (inetAddress == null) { + inetAddress = InetAddress.getLocalHost(); + } + Enumeration allNetInterfaces = null; allNetInterfaces = NetworkInterface.getNetworkInterfaces(); if (allNetInterfaces != null) { @@ -75,7 +71,7 @@ public static LinkedList getIpAddress() { } } } - } catch (SocketException e) { + } catch (Exception e) { e.printStackTrace(); } return ipList;