Search code examples
javainetaddress

How can i get the username and domain name of client system in java as i can get the ip address and host name using request.getRemoteHost


        out.print( "ip : "+request.getRemoteHost() );

        InetAddress ip=  InetAddress.getByName(""+request.getRemoteHost());

        String host=ip.getHostName();
        InetAddress host1=ip;
        out.print("host "+host); 

How can i get the username and domain name of client system in java as i can get the ip address and host name using request.getRemoteHost ..

using whoami am getting the server pc username. while i need the logged in username


Solution

  • You can find like below:

        System.out.println(System.getenv().get("USERDOMAIN"));
        System.out.println(System.getenv().get("USERNAME"));
    

    User name can be obtained as below:

        System.out.println(System.getProperty("user.name"));