Java Code Examples for eu.bitwalker.useragentutils.UserAgent#getOperatingSystem()
The following examples show how to use
eu.bitwalker.useragentutils.UserAgent#getOperatingSystem() .
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 File: URLUtil.java From boubei-tss with Apache License 2.0 | 6 votes |
public static String parseBrowser(String useragent) { useragent = (useragent + "").toLowerCase(); if(useragent.indexOf(browsers[0]) >= 0 && useragent.indexOf(browsers[1]) < 0) { // 微信客户端,注意区分QQ浏览器 return QQ_WX; } String origin = useragent; try { UserAgent userAgent = UserAgent.parseUserAgentString( useragent ); Browser browser = userAgent.getBrowser(); OperatingSystem opsys = userAgent.getOperatingSystem(); // 访问设备系统 Version browserVersion = userAgent.getBrowserVersion(); // 详细版本 String version = browserVersion.getMajorVersion(); // 浏览器主版本 origin = browser.getGroup().getName() + version + "-" + opsys; } catch(Exception e) { } for(String _b : browsers) { if(useragent.indexOf(_b) >= 0) { origin += "," + _b; break; } } return origin.toLowerCase(); }
Example 2
Source File: UEMServiceGFHandler.java From uavstack with Apache License 2.0 | 6 votes |
/** * getUA * * @param fdata * @param request */ private void getUA(StringBuilder fdata, HttpServletRequest request) { UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); String bwrVersion = userAgent.getBrowserVersion().getMajorVersion(); Browser bwr = userAgent.getBrowser(); String bwrType = bwr.getBrowserType().getName(); String bwrName = bwr.getName(); String bwrEngine = bwr.getRenderingEngine().name(); fdata.append(bwrName).append(";"); fdata.append(bwrType).append(";"); fdata.append(bwrEngine).append(";"); fdata.append(bwrVersion).append(";"); OperatingSystem os = userAgent.getOperatingSystem(); String osName = os.getName(); String deType = os.getDeviceType().getName(); fdata.append(osName).append(";"); fdata.append(deType).append(";"); }
Example 3
Source File: UaRule.java From kk-anti-reptile with Apache License 2.0 | 5 votes |
@Override protected boolean doExecute(HttpServletRequest request, HttpServletResponse response) { AntiReptileProperties.UaRule uaRule = properties.getUaRule(); UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); OperatingSystem os = userAgent.getOperatingSystem(); OperatingSystem osGroup = userAgent.getOperatingSystem().getGroup(); DeviceType deviceType = userAgent.getOperatingSystem().getDeviceType(); if (DeviceType.UNKNOWN.equals(deviceType)) { System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Unknown device, User-Agent: " + userAgent.toString()); return true; } else if (OperatingSystem.UNKNOWN.equals(os) || OperatingSystem.UNKNOWN_MOBILE.equals(os) || OperatingSystem.UNKNOWN_TABLET.equals(os)) { System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Unknown OperatingSystem, User-Agent: " + userAgent.toString()); return true; } if (!uaRule.isAllowedLinux() && (OperatingSystem.LINUX.equals(osGroup) || OperatingSystem.LINUX.equals(os))) { System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Linux request, User-Agent: " + userAgent.toString()); return true; } if (!uaRule.isAllowedMobile() && (DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType))) { System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Mobile Device request, User-Agent: " + userAgent.toString()); return true; } if (!uaRule.isAllowedPc() && DeviceType.COMPUTER.equals(deviceType)) { System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed PC request, User-Agent: " + userAgent.toString()); return true; } if (!uaRule.isAllowedIot() && (DeviceType.DMR.equals(deviceType) || DeviceType.GAME_CONSOLE.equals(deviceType) || DeviceType.WEARABLE.equals(deviceType))) { System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Iot Device request, User-Agent: " + userAgent.toString()); return true; } if (!uaRule.isAllowedProxy() && OperatingSystem.PROXY.equals(os)) { System.out.println("Intercepted request, uri: " + request.getRequestURI() + " Not Allowed Proxy request, User-Agent: " + userAgent.toString()); return true; } return false; }
Example 4
Source File: UserAgentUtils.java From app-version with Apache License 2.0 | 5 votes |
public static String getOS(String ua) { if (null == ua) return noDevice; UserAgent userAgent = UserAgent.parseUserAgentString(ua); OperatingSystem os = userAgent.getOperatingSystem(); return os.toString(); }
Example 5
Source File: HttpContextUtils.java From plumemo with Apache License 2.0 | 5 votes |
/** * 获取发起请求的操作系统名称 */ public static String getOsName(HttpServletRequest request) { try{ String header = request.getHeader("User-Agent"); UserAgent userAgent = UserAgent.parseUserAgentString(header); OperatingSystem operatingSystem = userAgent.getOperatingSystem(); return operatingSystem.getName(); }catch (Exception e){ return "not found osName"; } }
Example 6
Source File: BizCommentServiceImpl.java From OneBlog with GNU General Public License v3.0 | 5 votes |
/** * 保存当前评论时的设备信息 * * @param comment */ private void setCurrentDeviceInfo(Comment comment) { String ua = RequestUtil.getUa(); UserAgent agent = UserAgent.parseUserAgentString(ua); Browser browser = agent.getBrowser(); String browserInfo = browser.getName(); Version version = agent.getBrowserVersion(); if (version != null) { browserInfo += " " + version.getVersion(); } comment.setBrowser(browserInfo); OperatingSystem os = agent.getOperatingSystem(); comment.setOs(os.getName()); comment.setIp(RequestUtil.getIp()); }
Example 7
Source File: RequestListener.java From Spring-Boot-Book with Apache License 2.0 | 4 votes |
@Override public void requestDestroyed(ServletRequestEvent arg0) { System.out.println("监听器初始化..."); Integer count = null;//请求数量 Object requestCount = arg0.getServletContext().getAttribute("requestCount"); if (requestCount == null) { count = 0; } else { count = Integer.valueOf(requestCount.toString()); } count++; System.out.println("当前请求数:" + count.toString()); arg0.getServletContext().setAttribute("requestCount", count); /*用户信息*/ /*用户信息*/ HttpServletRequest servletRequest = (HttpServletRequest) arg0.getServletRequest(); //requestURL String requestURL = servletRequest.getRequestURL().toString(); //queryString String queryString = servletRequest.getQueryString(); RequestLog requestLog = new RequestLog(); requestLog.setIpaddr(IpUtils.getIpAddr(servletRequest)); requestLog.setSessionId(servletRequest.getRequestedSessionId()); requestLog.setReferer(servletRequest.getHeader("Referer")); requestLog.setAccept(servletRequest.getHeader("accept")); requestLog.setMethod(servletRequest.getMethod()); requestLog.setUrl(requestURL); requestLog.setQuerystring(queryString); /*UserAgent 工具类*/ UserAgent userAgent = UserAgent.parseUserAgentString(servletRequest.getHeader("User-Agent")); Browser browser = userAgent.getBrowser(); Version version = browser.getVersion(servletRequest.getHeader("User-Agent")); String browserInfo = null; try { browserInfo = browser.getName() + "/" + version.getVersion(); } catch (Exception e) { e.printStackTrace(); } OperatingSystem os = userAgent.getOperatingSystem(); /*UserAgent 工具类*/ requestLog.setOs(os.getName()); requestLog.setBrowser(browserInfo); requestLog.setCreationTimes(System.currentTimeMillis()); /* SecurityContextImpl securityContextImpl = (SecurityContextImpl) servletRequest.getSession().getAttribute("SPRING_SECURITY_CONTEXT"); requestLog.setLoginName( securityContextImpl.getAuthentication().getName());*/ requestLogRepository.save(requestLog); }
Example 8
Source File: UserAgentAnalysis.java From bbs with GNU Affero General Public License v3.0 | 4 votes |
/** * 解析 * String ua = request.getHeader("User-Agent"); * @param ua 请求头字段包含有关发起请求的用户代理的信息 */ public static AccessInfo analysis(String ua){ if(ua != null && !"".equals(ua.trim())){ //转成UserAgent对象 UserAgent userAgent = UserAgent.parseUserAgentString(ua); if(userAgent != null){ AccessInfo accessInfo = new AccessInfo(); //获取浏览器信息 Browser browser = userAgent.getBrowser(); if(browser != null){ String browserName = browser.getName();// 浏览器名称 accessInfo.setBrowserName(browserName);//浏览器名称 if(browser.getGroup() != null){ String group = browser.getGroup().getName();// 浏览器大类 accessInfo.setGroup(group);//浏览器大类 } } Version browserVersion = userAgent.getBrowserVersion();// 详细版本 if(browserVersion != null){ String version = browserVersion.getMajorVersion();// 浏览器主版本 accessInfo.setBrowserVersion(browserVersion.getVersion());//详细版本 accessInfo.setVersion(version);//浏览器主版本 } // System.out.println("浏览器名称 "+browserName); // System.out.println("浏览器大类 "+group); // System.out.println("详细版本 "+browserVersion); // System.out.println("浏览器主版本 "+version); // System.out.println("访问设备系统 "+userAgent.getOperatingSystem());// 访问设备系统 //系统名称 // String system = userAgent.getOperatingSystem().getName(); // System.out.println("访问设备类型 "+userAgent.getOperatingSystem().getDeviceType());// 访问设备类型 // System.out.println("访问设备制造厂商 "+userAgent.getOperatingSystem().getManufacturer());// 访问设备制造厂商 if(userAgent.getOperatingSystem() != null){ accessInfo.setOperatingSystem(userAgent.getOperatingSystem().toString());//访问设备系统 if(userAgent.getOperatingSystem().getDeviceType() != null && userAgent.getOperatingSystem().getDeviceType().getName() != null){ if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Computer")){ accessInfo.setDeviceType("电脑");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Mobile")){ accessInfo.setDeviceType("手机");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Tablet")){ accessInfo.setDeviceType("平板");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Game console")){ accessInfo.setDeviceType("游戏机");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Digital media receiver")){ accessInfo.setDeviceType("数字媒体接收器");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Wearable computer")){ accessInfo.setDeviceType("可穿戴设备");//访问设备类型 }else if(userAgent.getOperatingSystem().getDeviceType().getName().equals("Unknown")){ accessInfo.setDeviceType("未知设备");//访问设备类型 } } } return accessInfo; } } return null; }
Example 9
Source File: TailService.java From spring4ws-demos with Apache License 2.0 | 4 votes |
@Override public void handle(String line) { Matcher matcher = TailService.this.accessLogPattern.matcher(line); if (!matcher.matches()) { // System.out.println(line); return; } String ip = matcher.group(1); if (!"-".equals(ip) && !"127.0.0.1".equals(ip)) { CityResponse cr = lookupCity(ip); if (cr != null) { Access access = new Access(); access.setIp(ip); access.setDate(Instant.now().toEpochMilli()); access.setCity(cr.getCity().getName()); access.setCountry(cr.getCountry().getName()); String userAgent = matcher.group(9); UserAgent ua = UserAgent.parseUserAgentString(userAgent); if (ua != null) { String browserVersion = ua.getBrowserVersion() != null ? ua.getBrowserVersion().getVersion() : ""; if (browserVersion.equals("Unknown")) { browserVersion = ""; } String os = ua.getOperatingSystem() != null ? ua.getOperatingSystem().getName() : ""; if (os.equals("Unknown")) { os = ""; } String browser = ua.getBrowser() != null ? ua.getBrowser().getName() : ""; if (!browser.equals("Unknown")) { String uaString = String.join(" ", browser, browserVersion, os); access.setMessage(matcher.group(4) + "; " + uaString); } else { access.setMessage(matcher.group(4)); } } else { access.setMessage(null); } access.setLl(new Double[] { cr.getLocation().getLatitude(), cr.getLocation().getLongitude() }); TailService.this.messagingTemplate.convertAndSend("/topic/tail", access); } } }
Example 10
Source File: UserAgentUtils.java From momo-cloud-permission with Apache License 2.0 | 2 votes |
/** * 获取操作系统对象 * * @param request * @return */ private static OperatingSystem getOperatingSystem(String userAgent) { UserAgent agent = UserAgent.parseUserAgentString(userAgent); OperatingSystem operatingSystem = agent.getOperatingSystem(); return operatingSystem; }