当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletRequest.getRemoteAddr方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getRemoteAddr方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getRemoteAddr方法的具体用法?Java HttpServletRequest.getRemoteAddr怎么用?Java HttpServletRequest.getRemoteAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getRemoteAddr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRemoteIp

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * Pulls the remote IP from the current HttpServletRequest, or grabs the value
 * for the specified alternative attribute (say, for proxied requests).  Falls
 * back to providing the "normal" remote address if no value can be retrieved
 * from the specified alternative header value.
 * @param context the context
 * @return the remote ip
 */
private String getRemoteIp(@NotNull final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    String userAddress = request.getRemoteAddr();
    logger.debug("Remote Address = {}", userAddress);

    if (StringUtils.isNotBlank(this.alternativeRemoteHostAttribute)) {

        userAddress = request.getHeader(this.alternativeRemoteHostAttribute);
        logger.debug("Header Attribute [{}] = [{}]", this.alternativeRemoteHostAttribute, userAddress);

        if (StringUtils.isBlank(userAddress)) {
            userAddress = request.getRemoteAddr();
            logger.warn("No value could be retrieved from the header [{}]. Falling back to [{}].",
                    this.alternativeRemoteHostAttribute, userAddress);
        }
    }
    return userAddress;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:27,代码来源:BaseSpnegoKnownClientSystemsFilterAction.java

示例2: getIpAddr

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 获取ip工具类,除了getRemoteAddr,其他ip均可伪造
 * @param request
 * @return
 */
public static String getIpAddr(HttpServletRequest request) {
	String ip = request.getHeader("Cdn-Src-Ip");    // 网宿cdn的真实ip
	if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("HTTP_CLIENT_IP");   // 蓝讯cdn的真实ip
	}
	if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("X-Forwarded-For");  // 获取代理ip
	}
	if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("Proxy-Client-IP"); // 获取代理ip
	}
	if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("WL-Proxy-Client-IP"); // 获取代理ip
	}
	if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
		ip = request.getRemoteAddr(); // 获取真实ip
	}
	return ip;
}
 
开发者ID:javay,项目名称:zheng-lite,代码行数:25,代码来源:RequestUtil.java

示例3: address

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = "/address", method = POST, consumes = APPLICATION_JSON_UTF8_VALUE,
        produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<AddressResponse> address(@Valid @RequestBody AddressRequest addressRequest,
                                               @Valid @Size(max = Constants.UUID_CHAR_MAX_SIZE) @RequestHeader(value="Authorization") String authorizationHeader,
                                               @Context HttpServletRequest httpServletRequest)
        throws BaseException {
    // Get token
    String emailConfirmationToken = getEmailConfirmationToken(authorizationHeader);

    // Get IP address from request
    String ipAddress = httpServletRequest.getHeader("X-Real-IP");
    if (ipAddress == null)
        ipAddress = httpServletRequest.getRemoteAddr();
    LOG.info("/address called from {} with token {}, address {}, refundBTC {} refundETH {}",
            ipAddress,
            emailConfirmationToken,
            addressRequest.getAddress(),
            addressRequest.getRefundBTC(),
            addressRequest.getRefundETH());

    return setWalletAddress(addressRequest, emailConfirmationToken);
}
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:23,代码来源:AddressController.java

示例4: getRemoteIpAddress

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private String getRemoteIpAddress(HttpServletRequest request) {
    String ip = request.getHeader(requestHeaderProperties.getCustomRemoteIp());
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("X-Forwarded-For");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_CLIENT_IP");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_X_FORWARDED_FOR");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip;
}
 
开发者ID:superkoh,项目名称:k-framework,代码行数:23,代码来源:CommonInterceptor.java

示例5: getClientIp

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String getClientIp(HttpServletRequest request)
{
	String ip = request.getHeader("X-Real-IP");
	if(ip != null && ip.length() > 0 && !"null".equalsIgnoreCase(ip) && !"unKnown".equalsIgnoreCase(ip))
	{
		return ip;
	}
	ip = request.getHeader("X-Forwarded-For");
	if(ip != null && ip.length() > 0 && !"null".equalsIgnoreCase(ip) && !"unKnown".equalsIgnoreCase(ip))
	{
		// 多次反向代理后会有多个ip值,第一个ip才是真实ip
		int index = ip.indexOf(",");
		if(index != -1)
		{
			return ip.substring(0, index);
		}
		else
		{
			return ip;
		}
	}
	return request.getRemoteAddr();
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:24,代码来源:AuthController.java

示例6: toIpAddr

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * 返回用户的IP地址
 */
public static String toIpAddr(HttpServletRequest request) {
	String ip = request.getHeader("x-forwarded-for");
	if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("Proxy-Client-IP");
	}
	if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("WL-Proxy-Client-IP");
	}
	if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
		ip = request.getRemoteAddr();
	}
	return ip;
}
 
开发者ID:Awesky,项目名称:awe-awesomesky,代码行数:17,代码来源:CommonUtils.java

示例7: anyMethod

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@AfterThrowing(pointcut = "deptController() && anyMethod() " +
        "&& args(department, request)", throwing = "e")
public void handleAfterCreateDepartment(JoinPoint joinPoint,
                                        Department department, HttpServletRequest request, Throwable e) {
    int action = Integer.parseInt((((MethodSignature)joinPoint.getSignature())
            .getMethod()).getAnnotation(RequestMapping.class).name());
    AuditInfo auditRecord = new AuditInfo(department.getId(), null, request.getRemoteAddr(), department.toString(), action, e.getMessage());
    auditService.createRecord(auditRecord);
}
 
开发者ID:Witerium,项目名称:stuffEngine,代码行数:10,代码来源:AuditHandler.java

示例8: constructCredentialsFromRequest

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected Credential constructCredentialsFromRequest(final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final String remoteAddress = request.getRemoteAddr();

    if (StringUtils.hasText(remoteAddress)) {
        return new RemoteAddressCredential(remoteAddress);
    }

    logger.debug("No remote address found.");
    return null;
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:13,代码来源:RemoteAddressNonInteractiveCredentialsAction.java

示例9: testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithCustomValues

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Test
public void testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithCustomValues() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");
    filterDef.addInitParameter("remoteIpHeader", "x-my-forwarded-for");
    filterDef.addInitParameter("httpServerPort", "8080");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setSecure(true);
    request.setScheme("https");
    request.setHeader("x-my-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    boolean actualSecure = actualRequest.isSecure();
    assertFalse("request must be unsecured as header x-forwarded-proto said it is http", actualSecure);

    String actualScheme = actualRequest.getScheme();
    assertEquals("scheme must be http as header x-forwarded-proto said it is http", "http", actualScheme);

    int actualServerPort = actualRequest.getServerPort();
    assertEquals("wrong http server port", 8080, actualServerPort);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:35,代码来源:TestRemoteIpFilter.java

示例10: getIpAddr

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String getIpAddr(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip;
}
 
开发者ID:Yunfeng,项目名称:weixinpay,代码行数:14,代码来源:HomeController.java

示例11: getIpAddr

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public String getIpAddr(HttpServletRequest request) {      
	   String ip = request.getHeader("x-forwarded-for");      
	   if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {      
	       ip = request.getHeader("Proxy-Client-IP");      
	   }      
	   if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {      
	       ip = request.getHeader("WL-Proxy-Client-IP");      
	   }      
	   if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {      
	       ip = request.getRemoteAddr();      
	   }      
	   return ip;      
}
 
开发者ID:topicquests,项目名称:backside-servlet-ks,代码行数:14,代码来源:BaseHandler.java

示例12: getId

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
 * The ID that will identify the limit: the user login or the user IP address.
 */
private String getId(HttpServletRequest httpServletRequest) {
    String login = SecurityUtils.getCurrentUserLogin();
    if (login != null) {
        return login;
    } else {
        return httpServletRequest.getRemoteAddr();
    }
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:12,代码来源:RateLimitingFilter.java

示例13: login

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@GetMapping
public ModelAndView login(HttpServletRequest request) {
    log.info("Inside login method:: ");
    String ipAddress = request.getRemoteAddr();
    log.info("ipAddress from request: " + ipAddress);
    loginObj = new Login();
    loginObj.setClientIpAddress(ipAddress);
    return new ModelAndView("login", "loginObj", loginObj);
}
 
开发者ID:Mahidharmullapudi,项目名称:timesheet-upload,代码行数:10,代码来源:LoginController.java

示例14: filterAroundHandling

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Around("init()")
public Object filterAroundHandling(ProceedingJoinPoint joinPoint) throws Throwable {
  log.debug("around handing");
  //action
  MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
  Method action = methodSignature.getMethod();
  //接收到请求,记录请求内容
  ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  HttpServletRequest request = attributes.getRequest();
  //流控
  String clientIp = request.getRemoteAddr();
  String sessionId = request.getSession().getId();
  String requestUri = request.getRequestURI();
  String requestMethod = request.getMethod();
  long requestTimestamp = System.currentTimeMillis();
  flowControlService.flowController(clientIp, sessionId, requestUri, requestMethod, requestTimestamp, action.getDeclaredAnnotation(FlowControl.class));
  //过滤参数
  Map<String, String[]> filterParam = filterParamService.filterParam(request.getParameterMap(), action.getDeclaredAnnotation(FilterParam.class));
  //触发action, 完成参数校验部分
  Object object = joinPoint.proceed();
  log.debug("local response: {}", object);
  //透传
  PipeConfig pipeConfig = action.getAnnotation(PipeConfig.class);
  if (pipeConfig != null) {
    object = penetrationService.penetrate(request, action, methodSignature.getDeclaringType(), filterParam);
  }
  log.debug("penetration response: {}", object);
  return object;
}
 
开发者ID:chuangxian,项目名称:lib-edge,代码行数:30,代码来源:BeforeControllerAdvice.java

示例15: preGetDocument

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void preGetDocument() throws EngineException {
	HttpServletRequest request = (HttpServletRequest) inputData;
	
	HttpUtils.checkCV(request);

	String remoteAddr = request.getRemoteAddr();
	Engine.logContext.info("Remote-Addr: \"" + remoteAddr + "\"");
	context.remoteAddr = remoteAddr;
	Log4jHelper.mdcPut(mdcKeys.ClientIP, remoteAddr);

	String remoteHost = "-";
	context.remoteHost = remoteHost;
	if (EnginePropertiesManager.getProperty(PropertyName.NET_REVERSE_DNS).equalsIgnoreCase("true")) {
		remoteHost = request.getRemoteHost();
		if (remoteHost != null) {
			context.remoteHost = remoteHost;
			Log4jHelper.mdcPut(mdcKeys.ClientHostName, context.remoteHost);
			Engine.logContext.info("Remote-Host: \"" + remoteHost + "\"");
		}
	}
	
	String contextID = context.contextID;
	Engine.logContext.debug("Context ID: " + contextID);

	String requestURI = request.getRequestURI();
	Engine.logContext.debug("Request URI: " + requestURI);

	String servletPath = request.getServletPath();
	Engine.logContext.debug("Servlet path: " + servletPath);
	context.servletPath = servletPath;

	String queryString = request.getQueryString();
	Engine.logContext.info("Query string: " + queryString);

	String userAgent = request.getHeader(HeaderName.UserAgent.value());
	Engine.logContext.info("User-Agent: \"" + userAgent + "\"");
	context.userAgent = userAgent;

	try {
		HttpSessionListener.checkSession(request);
	} catch (TASException e) {
		HttpUtils.terminateSession(request.getSession());
		throw new RuntimeException(e);
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:46,代码来源:ServletRequester.java


注:本文中的javax.servlet.http.HttpServletRequest.getRemoteAddr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。