Results 1 to 2 of 2
  1. #1
    shahdharmit is offline Member
    Join Date
    Jul 2009
    Rep Power

    Question InetAddress.getLocalHost() issue...


    I am using Netbeans 6.7.1 on Fedora 11(Linux). The issue is that when I use InetAddress.getLocalHost() method, I get only the loopback interface IP. In Windows 7, I did same and got the IP that I was having. Right now in spite of being connected to the net and havinga live IP, I can't get that IP using the above mentioned method. Am I doing something wrong?


  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Rep Power


    There have been some reported issues with InetAddress.getLocalHost() in the past. If it's causing you trouble, you could try explicitly enumerating the interfaces:

    Java Code:
          Enumeration<NetworkInterface> infs = NetworkInterface.getNetworkInterfaces();
          while (infs.hasMoreElements()) {
            NetworkInterface inf = infs.nextElement();
            System.out.println("Name : " + inf.getName());
            Enumeration<InetAddress> addrs = inf.getInetAddresses();
            while (addrs.hasMoreElements()) {
              System.out.println("  " + addrs.nextElement().getHostAddress());
    N.B. Neither InetAddress.getLocalHost() or NetworkInterface will provide the local IP if the security policy you're running with doesn't allow it. This usually applies to Applets.

Similar Threads

  1. PDF Box issue
    By jazz2k8 in forum Advanced Java
    Replies: 0
    Last Post: 03-20-2009, 12:04 PM
  2. Session issue
    By jazz2k8 in forum Advanced Java
    Replies: 3
    Last Post: 11-23-2008, 03:07 AM
  3. convert InetAddress to a string
    By hunterbdb in forum New To Java
    Replies: 4
    Last Post: 10-18-2008, 10:50 AM
  4. Issue
    By chaitu444 in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 08:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts