content: package top.arkstack.shine.mq.util;
  
  import java.net.Inet4Address;
  import java.net.InetAddress;
  import java.net.NetworkInterface;
  import java.util.Enumeration;
  
  /**
   * 工具类
   *
   * @author 7le
   * @version 2.0.0
   */
  public class HttpUtil {
  
      public static String getIpAddress() {
          try {
              Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
              InetAddress ip;
              while (allNetInterfaces.hasMoreElements()) {
                  NetworkInterface netInterface = allNetInterfaces.nextElement();
                  if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
                      continue;
                  } else {
                      Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
                      while (addresses.hasMoreElements()) {
                          ip = addresses.nextElement();
                          if (ip instanceof Inet4Address) {
                              return ip.getHostAddress();
                          }
                      }
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
          return "";
      }
  }
  