예제 #1
0
 /**
  * 取得本机IP地址 (多网卡主机返回其中一张网卡的IP)
  *
  * @param isInter 是否返回内网IP(默认网段为19.2.)
  * @return 本机ip地址
  */
 public static synchronized String getLocalIP(boolean isInter) {
   // 初始化本地地址列表
   if (localAddressList == null) {
     localAddressList = getLocalAddresses();
   }
   String localIP = "";
   for (InetAddress ia : localAddressList) {
     String ip = ia.getHostAddress();
     // 忽略ipv6地址和loopback地址
     if (ia instanceof Inet6Address || ip.startsWith("127")) {
       continue;
     }
     // 记录找到的第一个ipv4地址
     if (StringUtil.isNullOrBlank(localIP)) {
       localIP = ip;
     }
     if (isInter && ip.startsWith("19.")) {
       return ip;
     }
     if (!isInter && !ip.startsWith("19.")) {
       return ip;
     }
   }
   return localIP;
 }
예제 #2
0
  /*
   * 获取用户的网络出口端口号  网络层配置
   */
  public static int getUserPort(HttpServletRequest request) {
    String portStr = request.getParameter("Ty_Remote_Port");
    if (StringUtil.isNullOrBlank(portStr)) {
      return request.getRemotePort();
    }

    try {
      return Integer.parseInt(portStr);
    } catch (NumberFormatException e) {
      return request.getRemotePort();
    }
  }