No, it's not a problem, it's simply an output that consists of hostname and IP (
hostname/ip
). A detail that you might want to read up: The methodtoString()
in the classInetAddress
is implemented to return this format.The following code will list all IP addresses for each of the interfaces in your system (and also stores them in a list that you could then pass on etc...):
public static void main(String[] args) throws InterruptedException, IOException { List<String> allIps = new ArrayList<String>(); Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface n = e.nextElement(); System.out.println(n.getName()); Enumeration<InetAddress> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = ee.nextElement(); System.out.println(i.getHostAddress()); allIps.add(i.getHostAddress()); } } }
The method boolean isLoopbackAddress()
allows you to filter the potentially unwanted loopback addresses.
The returned InetAddress
is either a Inet4Address
or a Inet6Address
, using the instanceof
you can figure out if the returned IP is IPv4 or IPv6 format.