Search code examples
javanetwork-programmingserversocket

Java - ServerSocket IP Address


After I opened a server socket, I would like to access its IP address (the one others can use to connect to). When I call

ServerSocket seso = new ServerSocket(port);
System.out.println(seso.getInetAddress());

it displays (0.0.0.0/0.0.0.0), which is only the net mask. What I would like to get is the ip the socket was actually bound to, e.g. 130.75.22.12 (or something similar).


Solution

  • Freeze

    It seems you are searching for water in a desert :).

    You can't get the ip address of the ServerSocket which listens to all interfaces in the computer or from any ip address.(Before a device or program connects to the ServerSocket).So for querying all the networking interface's ip address jz follow the link to make a study and use those ip addresses to acheive what you need..

    Oracle Java Documentation - Querying Network Interface Addresses.

    It seems it would be helpful for everyone.