Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Client's Computer Name

  1. #1
    Join Date
    Oct 2013
    Manila, Philippines
    My Mood
    Thanked 64 Times in 61 Posts

    Default Client's Computer Name

    Hi Everyone.
    I have a problem getting the client's computer name. (Actually I don't know how, and can't find it either in google search)

    This is a Web project.
    Below is a example code:

    import java.net.InetAddress;
    import java.net.UnknownHostException;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    import javax.servlet.http.HttpServletRequest;
    @ManagedBean(name = "domain")
    public class DomainTest extends BasePageBean {
        public void testDomain() throws UnknownHostException {
            HttpServletRequest request = getRequest(); // HttpServlet request created in BasePageBean class
            String ipAddress = request.getHeader("X-Real-IP");
            if (ipAddress == null) {
                ipAddress = request.getRemoteAddr();
            System.out.println("Local Address " + request.getLocalAddr());
            System.out.println("User " + request.getRemoteUser());
            System.out.println("Host " + request.getRemoteHost());
            InetAddress i = InetAddress.getByName(request.getRemoteAddr());
            System.out.println("Inet Address " + i);
            System.out.println("Computer Name " + i.getHostName());

    The BasePageBean is also a java program that Initialized the HttpServletRequest and HttpServletResponse.
    I just need to inherit it for each page in the web project. I hope you get it

    The problem is, once i deployed the project in our UNIX server, and run it through my computer, the output I got is always IP Address

    Sample output:
    Local Address
    User null
    Inet Address /
    Computer Name


    That kind of algorithm will work if it is not a web project. For example a simple java program that you can run in your machine
    Example Code:
    import java.net.InetAddress;
    import java.net.SocketException;
    import java.net.UnknownHostException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    public class TestDomain {
        public static void main(String[] args) throws SocketException {
            try {
                InetAddress i = InetAddress.getByName("");
            } catch (UnknownHostException ex) {
                Logger.getLogger(TestDomain.class.getName()).log(Level.SEVERE, null, ex);
    Above code will give an output of:

    Since its getting the info from where the program runs.

    So I'm having a problem once I implement it through web and deploy it to our UNIX server.

    If the above algorithm is capable of getting the username of client's machine please help me.
    If not, is there any other way of getting the username of client's machine? thank you!

    I need it so that our web project can log in the client using the client's username..

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    So. Maryland, USA
    My Mood
    Thanked 697 Times in 679 Posts

    Default Re: Client's Computer Name

    Thread moved.

Similar Threads

  1. I Love computer
    By ganesh arora in forum Member Introductions
    Replies: 2
    Last Post: January 13th, 2014, 06:35 AM
  2. Want NEW computer!
    By sci4me in forum Totally Off Topic
    Replies: 2
    Last Post: July 12th, 2013, 01:37 AM
  3. my encrypting simple client to server program unable to get the key from client
    By Paytheprice in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 3rd, 2013, 07:15 AM
  4. Replies: 0
    Last Post: May 31st, 2012, 05:35 PM
  5. server/client application fails when client closes
    By billykid in forum Java Networking
    Replies: 4
    Last Post: January 26th, 2012, 01:54 AM