1

I wanna test my program with VMWare. So I've run the program in a VMWare. Using ipconfig command on that machine gives me some IP like 192.168.XXX.XXX. It has a server socket listening on some port, on this IP. When someone needs to speak with it, it connect to this 192.168.xxx.xxx IP fine (using Socket s = new Socket(IP, port)). But when inside the program I call socket.getInetAdress() which should return the 192.168.x.x IP, it returns 0.0.0.0 instead, and the simulation fails.

What can I do? Thanx in advance :)

Joe
  • 41,484
  • 20
  • 104
  • 125
Ameer Jewdaki
  • 1,758
  • 4
  • 21
  • 36

3 Answers3

1

0.0.0.0 means the socket is bound to all available local IP addresses, not a specific IP address. That is normal for listening servers that are bound using wildcard IPs.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
1

This is a Java issue rather than a VMWare issue. I'm assuming that you're trying to get your machine's IP rather than just the ip that the server is bound to. In that case, see this question for some proposed solutions: java InetAddress.getLocalHost(); returns 127.0.0.1 ... how to get REAL IP?

Community
  • 1
  • 1
Jon7
  • 7,165
  • 2
  • 33
  • 39
0

This is likely because things like InetAddress.getLocalHost(); get the hostname and then lookup the ipAddress from it. If your vm resolves that hostname to localhost, then you will get 127.0.0.1. This is likely what is happening. You need to get the ip address from the external network interface.

Try running this:

Enumeration netInterfaces=NetworkInterface.getNetworkInterfaces();
    while(netInterfaces.hasMoreElements()){
        NetworkInterface ni=(NetworkInterface)netInterfaces.nextElement();          
        InetAddress ip=(InetAddress) ni.getInetAddresses().nextElement();
        System.out.println(ni.getName()+" "+ip.getAddress());
    }
Jason Clawson
  • 1,027
  • 7
  • 9