Getting IP Address

Is there a function that returns the IP Adress?

Inet Address.getHostAddress().

Keith

depends what IP adress you need. If it’s from local computer it can be from LAN or WAN.

How come InetAdress.getHostAdress() is giving me “0.0.0.0” :’(?



Serversocket listener;

public void open(int port){
    try {
        listener = new ServerSocket(port);
        System.out.println(listener.getInetAddress().getHostAddress());
    }
    catch (IOException e){
    }
}


public static InetAddress getLocalHost() throws UnknownHostException

getLocalHost().getHostAddress()

getHostAddress() is only returining the IP of adress in a String

Edit: ah didn’t noticed your code…
when listening, programs listen on 0.0.0.0 … don’t know why or in what cases, look in your firewall / netlimiter, it’s like that. If you just want localhost address the above works.