Java Code Examples for com.ruoyi.common.utils.IpUtils

The following examples show how to use com.ruoyi.common.utils.IpUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: supplierShop   Source File: OnlineSessionFactory.java    License: MIT License 6 votes vote down vote up
@Override
public Session createSession(SessionContext initData)
{
    OnlineSession session = new OnlineSession();
    if (initData != null && initData instanceof WebSessionContext)
    {
        WebSessionContext sessionContext = (WebSessionContext) initData;
        HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
        if (request != null)
        {
            UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
            // 获取客户端操作系统
            String os = userAgent.getOperatingSystem().getName();
            // 获取客户端浏览器
            String browser = userAgent.getBrowser().getName();
            session.setHost(IpUtils.getIpAddr(request));
            session.setBrowser(browser);
            session.setOs(os);
        }
    }
    return session;
}
 
Example 2
Source Project: supplierShop   Source File: LogUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 记录访问日志 [username][jsessionid][ip][accept][UserAgent][url][params][Referer]
 *
 * @param request
 * @throws Exception
 */
public static void logAccess(HttpServletRequest request) throws Exception
{
    String username = getUsername();
    String jsessionId = request.getRequestedSessionId();
    String ip = IpUtils.getIpAddr(request);
    String accept = request.getHeader("accept");
    String userAgent = request.getHeader("User-Agent");
    String url = request.getRequestURI();
    String params = getParams(request);

    StringBuilder s = new StringBuilder();
    s.append(getBlock(username));
    s.append(getBlock(jsessionId));
    s.append(getBlock(ip));
    s.append(getBlock(accept));
    s.append(getBlock(userAgent));
    s.append(getBlock(url));
    s.append(getBlock(params));
    s.append(getBlock(request.getHeader("Referer")));
    getAccessLog().info(s.toString());
}
 
Example 3
Source Project: ruoyiplus   Source File: OnlineSessionFactory.java    License: MIT License 6 votes vote down vote up
@Override
public Session createSession(SessionContext initData)
{
    OnlineSession session = new OnlineSession();
    if (initData != null && initData instanceof WebSessionContext)
    {
        WebSessionContext sessionContext = (WebSessionContext) initData;
        HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
        if (request != null)
        {
            UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
            // 获取客户端操作系统
            String os = userAgent.getOperatingSystem().getName();
            // 获取客户端浏览器
            String browser = userAgent.getBrowser().getName();
            session.setHost(IpUtils.getIpAddr(request));
            session.setBrowser(browser);
            session.setOs(os);
        }
    }
    return session;
}
 
Example 4
Source Project: ruoyiplus   Source File: LogUtils.java    License: MIT License 6 votes vote down vote up
/**
 * 记录访问日志 [username][jsessionid][ip][accept][UserAgent][url][params][Referer]
 *
 * @param request
 * @throws Exception
 */
public static void logAccess(HttpServletRequest request) throws Exception
{
    String username = getUsername();
    String jsessionId = request.getRequestedSessionId();
    String ip = IpUtils.getIpAddr(request);
    String accept = request.getHeader("accept");
    String userAgent = request.getHeader("User-Agent");
    String url = request.getRequestURI();
    String params = getParams(request);

    StringBuilder s = new StringBuilder();
    s.append(getBlock(username));
    s.append(getBlock(jsessionId));
    s.append(getBlock(ip));
    s.append(getBlock(accept));
    s.append(getBlock(userAgent));
    s.append(getBlock(url));
    s.append(getBlock(params));
    s.append(getBlock(request.getHeader("Referer")));
    getAccessLog().info(s.toString());
}
 
Example 5
Source Project: RuoYi   Source File: OnlineSessionFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Session createSession(SessionContext initData) {
    OnlineSession session = new OnlineSession();
    if (initData instanceof WebSessionContext) {
        WebSessionContext sessionContext = (WebSessionContext) initData;
        HttpServletRequest request = (HttpServletRequest) sessionContext.getServletRequest();
        if (request != null) {
            UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
            // 获取客户端操作系统
            String os = userAgent.getOperatingSystem().getName();
            // 获取客户端浏览器
            String browser = userAgent.getBrowser().getName();
            session.setHost(IpUtils.getIpAddr(request));
            session.setBrowser(browser);
            session.setOs(os);
        }
    }
    return session;
}
 
Example 6
Source Project: RuoYi   Source File: LogUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 记录访问日志 [username][jsessionid][ip][accept][UserAgent][url][params][Referer]
 *
 * @param request
 * @throws Exception
 */
public static void logAccess(HttpServletRequest request) throws Exception {
    String username = getUsername();
    String ip = IpUtils.getIpAddr(request);
    String accept = request.getHeader("accept");
    String userAgent = request.getHeader("User-Agent");
    String url = request.getRequestURI();
    String params = getParams(request);

    String s = getBlock(username) +
            getBlock(request.getRequestedSessionId()) +
            getBlock(ip) +
            getBlock(accept) +
            getBlock(userAgent) +
            getBlock(url) +
            getBlock(params) +
            getBlock(request.getHeader("Referer"));
    getAccessLog().info(s);
}
 
Example 7
Source Project: supplierShop   Source File: Server.java    License: MIT License 5 votes vote down vote up
/**
 * 设置服务器信息
 */
private void setSysInfo()
{
    Properties props = System.getProperties();
    sys.setComputerName(IpUtils.getHostName());
    sys.setComputerIp(IpUtils.getHostIp());
    sys.setOsName(props.getProperty("os.name"));
    sys.setOsArch(props.getProperty("os.arch"));
    sys.setUserDir(props.getProperty("user.dir"));
}
 
Example 8
Source Project: supplierShop   Source File: LogUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 记录页面错误 错误日志记录 [page/eception][username][statusCode][errorMessage][servletName][uri][exceptionName][ip][exception]
 *
 * @param request
 */
public static void logPageError(HttpServletRequest request)
{
    String username = getUsername();

    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    String message = (String) request.getAttribute("javax.servlet.error.message");
    String uri = (String) request.getAttribute("javax.servlet.error.request_uri");
    Throwable t = (Throwable) request.getAttribute("javax.servlet.error.exception");

    if (statusCode == null)
    {
        statusCode = 0;
    }

    StringBuilder s = new StringBuilder();
    s.append(getBlock(t == null ? "page" : "exception"));
    s.append(getBlock(username));
    s.append(getBlock(statusCode));
    s.append(getBlock(message));
    s.append(getBlock(IpUtils.getIpAddr(request)));

    s.append(getBlock(uri));
    s.append(getBlock(request.getHeader("Referer")));
    StringWriter sw = new StringWriter();

    while (t != null)
    {
        t.printStackTrace(new PrintWriter(sw));
        t = t.getCause();
    }
    s.append(getBlock(sw.toString()));
    getErrorLog().error(s.toString());

}
 
Example 9
Source Project: ruoyiplus   Source File: Server.java    License: MIT License 5 votes vote down vote up
/**
 * 设置服务器信息
 */
private void setSysInfo()
{
    Properties props = System.getProperties();
    sys.setComputerName(IpUtils.getHostName());
    sys.setComputerIp(IpUtils.getHostIp());
    sys.setOsName(props.getProperty("os.name"));
    sys.setOsArch(props.getProperty("os.arch"));
    sys.setUserDir(props.getProperty("user.dir"));
}
 
Example 10
Source Project: ruoyiplus   Source File: LogUtils.java    License: MIT License 5 votes vote down vote up
/**
 * 记录页面错误 错误日志记录 [page/eception][username][statusCode][errorMessage][servletName][uri][exceptionName][ip][exception]
 *
 * @param request
 */
public static void logPageError(HttpServletRequest request)
{
    String username = getUsername();

    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    String message = (String) request.getAttribute("javax.servlet.error.message");
    String uri = (String) request.getAttribute("javax.servlet.error.request_uri");
    Throwable t = (Throwable) request.getAttribute("javax.servlet.error.exception");

    if (statusCode == null)
    {
        statusCode = 0;
    }

    StringBuilder s = new StringBuilder();
    s.append(getBlock(t == null ? "page" : "exception"));
    s.append(getBlock(username));
    s.append(getBlock(statusCode));
    s.append(getBlock(message));
    s.append(getBlock(IpUtils.getIpAddr(request)));

    s.append(getBlock(uri));
    s.append(getBlock(request.getHeader("Referer")));
    StringWriter sw = new StringWriter();

    while (t != null)
    {
        t.printStackTrace(new PrintWriter(sw));
        t = t.getCause();
    }
    s.append(getBlock(sw.toString()));
    getErrorLog().error(s.toString());

}
 
Example 11
Source Project: RuoYi   Source File: Server.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置服务器信息
 */
private void setSysInfo() {
    Properties props = System.getProperties();
    sys.setComputerName(IpUtils.getHostName());
    sys.setComputerIp(IpUtils.getHostIp());
    sys.setOsName(props.getProperty("os.name"));
    sys.setOsArch(props.getProperty("os.arch"));
    sys.setUserDir(props.getProperty("user.dir"));
}
 
Example 12
Source Project: RuoYi   Source File: LogUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 记录页面错误 错误日志记录 [page/eception][username][statusCode][errorMessage][servletName][uri][exceptionName][ip][exception]
 *
 * @param request
 */
public static void logPageError(HttpServletRequest request) {
    String username = getUsername();

    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    String message = (String) request.getAttribute("javax.servlet.error.message");
    String uri = (String) request.getAttribute("javax.servlet.error.request_uri");
    Throwable t = (Throwable) request.getAttribute("javax.servlet.error.exception");

    if (statusCode == null) {
        statusCode = 0;
    }

    StringBuilder s = new StringBuilder();
    s.append(getBlock(t == null ? "page" : "exception"));
    s.append(getBlock(username));
    s.append(getBlock(statusCode));
    s.append(getBlock(message));
    s.append(getBlock(IpUtils.getIpAddr(request)));

    s.append(getBlock(uri));
    s.append(getBlock(request.getHeader("Referer")));
    StringWriter sw = new StringWriter();

    while (t != null) {
        t.printStackTrace(new PrintWriter(sw));
        t = t.getCause();
    }
    s.append(getBlock(sw.toString()));
    String msg = s.toString();
    getErrorLog().error(msg);

}