본체 운영체제, ip, 브라우저 정보 얻기

2543 단어
public class ComputerUtils {
    /**
     * @function      ip
     * @author heng.fu
     * @date 2017 7 19    2:22:03
     * @param @return
     * @return String
     */
    public static String getHostAddress(){
         InetAddress addr;
         String ip = null;
        try {
            addr = InetAddress.getLocalHost();
            ip = addr.getHostAddress().toString(); //    ip
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
         return ip;
    }
    
    /**
     * @function           
     * @author heng.fu
     * @date 2017 7 19    2:24:12
     * @param @return
     * @return String
     */
    public static String getOsName(){
         Properties props = System.getProperties();
         String osName = props.getProperty("os.name");
         return osName;
    }
    
    /**
     *      IP
     * @Title: getBroAddress
     * @param @param request
     * @param @return        
     * @return String        
     * @throws 
     * @author peng.ou 
     * @date 2017 9 7    10:43:34
     */
    public static String getBroAddress(HttpServletRequest request){
        return request.getRemoteAddr();
    }
    
    /**
     *        
     * @Title: getBroOsName
     * @param @param request
     * @param @return        
     * @return String        
     * @throws 
     * @author peng.ou 
     * @date 2017 9 7    10:48:42
     */
    public static String getBroOsName(HttpServletRequest request){
        //       
        UserAgent agent = UserAgent.parseUserAgentString(request.getHeader("user-agent")); 
        //      
        OperatingSystem os = agent.getOperatingSystem();  
       /* System.out.println("  :"+os.getName()+  
                "
:"+os.getDeviceType()+ "
:"+os.getGroup()+ "
:"+os.getManufacturer()); */ return os.getName(); } /** * @function / * @author heng.fu * @date 2017 7 19 2:29:57 * @param @param request * @param @return * @return String */ public static String getBrowser(HttpServletRequest request){ // Browser browser = UserAgent.parseUserAgentString(request.getHeader("User-Agent")).getBrowser(); // Version version = browser.getVersion(request.getHeader("User-Agent")); String info = browser.getName() + "/" + version.getVersion(); return info; } }

좋은 웹페이지 즐겨찾기