Here you can find the source of getIPs()
public static String getIPs()
//package com.java2s; //License from project: Open Source License import java.net.SocketException; import java.net.NetworkInterface; import java.net.InetAddress; import java.net.Inet4Address; import java.util.Enumeration; public class Main { public static String getIPs() { try {// ww w . j a v a 2s . c o m Enumeration<NetworkInterface> nets; NetworkInterface n; Enumeration<InetAddress> addrs; InetAddress a; String s = ""; nets = NetworkInterface.getNetworkInterfaces(); while (nets.hasMoreElements()) { n = nets.nextElement(); if (n.isUp()) { s += n.getName() + "\n"; addrs = n.getInetAddresses(); while (addrs.hasMoreElements()) { a = addrs.nextElement(); if (a instanceof Inet4Address) { s += " * " + a.getHostAddress() + "\n"; } } } } return s.trim(); } catch (SocketException e) { System.out .println("Error: couldn't get ip addresses for network interfaces"); return ""; } } }