Class NetUtils

java.lang.Object
cool.scx.common.util.NetUtils

public final class NetUtils extends Object
基本网络操作工具类
Version:
0.0.1
Author:
scx567888
  • Constructor Details

    • NetUtils

      public NetUtils()
  • Method Details

    • getClientIPAddress

      public static String getClientIPAddress(io.vertx.core.http.HttpServerRequest request)
      获取访问者IP

      先从Header中获取X-Real-IP,如果不存在再从X-Forwarded-For获得第一个IP(用,分割), 如果还不存在则调用 HttpServerRequest.remoteAddress()

      Parameters:
      request - a
      Returns:
      IP
    • getLocalIPAddress

      public static InetAddress[] getLocalIPAddress(Predicate<InetAddress> filter) throws SocketException
      获取本机的 IP 地址 (不包括回环地址)
      Returns:
      本机的 IP 地址
      Throws:
      SocketException
    • getLocalIPAddress

      public static InetAddress[] getLocalIPAddress() throws SocketException
      Throws:
      SocketException