public static ArrayList<String> getLocalIpAddr()
{
ArrayList<String> ipList = new ArrayList<String>();
InetAddress[] addrList;
try
{
Enumeration interfaces=NetworkInterface.getNetworkInterfaces();
while(interfaces.hasMoreElements())
{
NetworkInterface ni=(NetworkInterface)interfaces.nextElement();
Enumeration ipAddrEnum = ni.getInetAddresses();
while(ipAddrEnum.hasMoreElements())
{
InetAddress addr = (InetAddress)ipAddrEnum.nextElement();
if (addr.isLoopbackAddress() == true)
{
continue;
}
String ip = addr.getHostAddress();
if (ip.indexOf(":") != -1)
{
//skip the IPv6 addr
continue;
}
ipList.add(ip);
}
}
Collections.sort(ipList);
}
catch (Exception e)
{
e.printStackTrace();
}
return ipList;
}