Ver Mensaje Individual
  #9 (permalink)  
Antiguo 23/04/2013, 14:47
1chencho1
 
Fecha de Ingreso: febrero-2013
Mensajes: 25
Antigüedad: 11 años, 2 meses
Puntos: 2
Respuesta: Obtener la IP en java

Cita:
Iniciado por Fuzzylog Ver Mensaje
Prueba esto (sacado de): [url]http://stackoverflow.com/questions/4871451/inetaddress-getlocalhost-returns-wrong-result-when-hostname-is-64-chars[/url]

try {
// Replace eth0 with your interface name
NetworkInterface i = NetworkInterface.getByName("eth0");

if (i != null) {

Enumeration<InetAddress> iplist = i.getInetAddresses();

InetAddress addr = null;

while (iplist.hasMoreElements()) {
InetAddress ad = iplist.nextElement();
byte bs[] = ad.getAddress();
if (bs.length == 4 && bs[0] != 127) {
addr = ad;
// You could also display the host name here, to
// see the whole list, and remove the break.
break;
}
}

if (addr != null) {
System.out.println( addr.getCanonicalHostName() );
}
} catch (...) { ... }
Mañana intentaré probar, muchas gracias amigo!!