Advertisement
juliomzt

Inet

Jun 1st, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.net.InetAddress;
  2. import java.net.UnknownHostException;
  3.  
  4. /**
  5.  *
  6.  * @author Julio Chinchilla
  7.  */
  8. public class Inet {
  9.    
  10.     /**
  11.      * Devuelve un arreglo mostrando todas las ip del host a consultar
  12.      * @param url
  13.      * @return
  14.      * @throws UnknownHostException
  15.      */
  16.     public static String[] getAllIP(String url) throws UnknownHostException {
  17.         InetAddress[] inetAddresses = InetAddress.getAllByName(url);
  18.         String [] res = new String[inetAddresses.length];
  19.         int i = 0;
  20.         for (InetAddress ipAddress : inetAddresses) {
  21.             res[i] = ipAddress.toString();
  22.             i++;
  23.         }
  24.         return res;
  25.     }
  26.    
  27.     /**
  28.      * Devuelve la ip local de la máquina
  29.      * @return String IP del host donde se ejecutó
  30.      * @throws UnknownHostException
  31.      */
  32.     public static String getLocalIP () throws UnknownHostException {
  33.         InetAddress ip = InetAddress.getLocalHost();
  34.     return ip.getHostAddress();
  35.     }
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement