Java IP Address Get getAllHostIPs(String hostName)

Here you can find the source of getAllHostIPs(String hostName)

Description

get All Host I Ps

License

Apache License

Declaration

public static List<String> getAllHostIPs(String hostName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> getAllHostIPs(String hostName) {
        List<String> ips = null;
        try {/*ww  w .  j  a  va 2s .co  m*/
            InetAddress[] addrs = InetAddress.getAllByName(hostName);
            if (null != addrs && addrs.length > 0) {
                ips = new ArrayList<String>();
                for (int i = 0; i < addrs.length; i++) {
                    ips.add(addrs[i].getHostAddress());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ips;
    }
}

Related

  1. getAllHostAddresses(boolean ignoreLoopback, boolean ignoreIP6)
  2. getAllInternalHostIPs(String hostName)
  3. getAllIp()
  4. getAllIPAddresses()
  5. getAllIPsAndAssignedBroadcastAddresses()