public static InetAddress getAddress ( ) { try { return InetAddress . getByAddress ( new byte [ ] { 0 , 0 , 0 , 0 } ) ; /*for (Enumeration e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) { NetworkInterface ni = (NetworkInterface) e.nextElement(); System.out.println("NetworkInterface = " + ni.getName()); if (!ni.getName().contains("lo")) { for (Enumeration ee = ni.getInetAddresses(); ee.hasMoreElements();) { InetAddress ip = (InetAddress) ee.nextElement(); if (ip instanceof Inet4Address && ip.getAddress() != null) { return ip; } //System.out.println("Ip's: " + ip.getHostAddress()); } } } NetworkInterface lo = NetworkInterface.getByName("lo"); if (lo != null) { for (Enumeration ee = lo.getInetAddresses(); ee.hasMoreElements();) { InetAddress ip = (InetAddress) ee.nextElement(); if (ip instanceof Inet4Address && ip.getAddress() != null) { return ip; } } } NetworkInterface lo0 = NetworkInterface.getByName("lo0"); if (lo0 != null) { for (Enumeration ee = lo0.getInetAddresses(); ee.hasMoreElements();) { InetAddress ip = (InetAddress) ee.nextElement(); if (ip instanceof Inet4Address && ip.getAddress() != null) { return ip; } } }*/ } catch ( Exception e ) { System . err . println ( "Error" ) ; } return null ; }
This method returns the address of the machine . It is needed to successfully communicate with emulators hosted into other machines .