Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- /**
- *
- * @author Julio Chinchilla
- */
- public class Inet {
- /**
- * Devuelve un arreglo mostrando todas las ip del host a consultar
- * @param url
- * @return
- * @throws UnknownHostException
- */
- public static String[] getAllIP(String url) throws UnknownHostException {
- InetAddress[] inetAddresses = InetAddress.getAllByName(url);
- String [] res = new String[inetAddresses.length];
- int i = 0;
- for (InetAddress ipAddress : inetAddresses) {
- res[i] = ipAddress.toString();
- i++;
- }
- return res;
- }
- /**
- * Devuelve la ip local de la máquina
- * @return String IP del host donde se ejecutó
- * @throws UnknownHostException
- */
- public static String getLocalIP () throws UnknownHostException {
- InetAddress ip = InetAddress.getLocalHost();
- return ip.getHostAddress();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement