Java Utililty Methods IP Address Get

List of utility methods to do IP Address Get

Description

The list of methods to do IP Address Get are organized into topic(s).

Method

InetAddress[]getAllHostAddresses(boolean ignoreLoopback, boolean ignoreIP6)
Returns all IP addresses that could be found on this machine.
ArrayList<InetAddress> list = new ArrayList<InetAddress>();
try {
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface networkInterface = interfaces.nextElement();
        getAllHostAddresses(networkInterface, list, ignoreLoopback, ignoreIP6);
} catch (SocketException e) {
...
ListgetAllHostIPs(String hostName)
get All Host I Ps
List<String> ips = null;
try {
    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;
ListgetAllInternalHostIPs(String hostName)
get All Internal Host I Ps
List<String> ips = null;
try {
    InetAddress[] addrs = InetAddress.getAllByName(hostName);
    if (null != addrs && addrs.length > 0) {
        ips = new ArrayList<String>();
        for (int i = 0; i < addrs.length; i++) {
            String ip = addrs[i].getHostAddress();
            if (isInnerIP(ip))
...
ListgetAllIp()
get All Ip
List<String> result = new ArrayList<>();
Enumeration<NetworkInterface> infs = NetworkInterface.getNetworkInterfaces();
while (infs.hasMoreElements()) {
    NetworkInterface inf = infs.nextElement();
    if (!inf.isUp() || inf.isVirtual()) {
        continue;
    Enumeration<InetAddress> addrs = inf.getInetAddresses();
...
CollectiongetAllIPAddresses()
Retrieves all the IP addresses of the local computer.
ArrayList<InterfaceAddress> direcciones = new ArrayList();
InterfaceAddress ipLoopback = null;
try {
    Enumeration ifaces = NetworkInterface.getNetworkInterfaces();
    while (ifaces.hasMoreElements()) {
        NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
        for (InterfaceAddress ips : iface.getInterfaceAddresses()) {
            InetAddress ia = ips.getAddress();
...
HashMapgetAllIPsAndAssignedBroadcastAddresses()
Get a mapping of all assigned IP-addresses to their according broadcast addresses
HashMap<InetAddress, InetAddress> ipAndBroadcastAddresses = new HashMap<InetAddress, InetAddress>();
Enumeration<?> networkInterfaces;
networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
    NetworkInterface networkInterface = (NetworkInterface) networkInterfaces.nextElement();
    if (networkInterface != null && !networkInterface.isLoopback() && networkInterface.isUp()) {
        Iterator<?> it = networkInterface.getInterfaceAddresses().iterator();
        while (it.hasNext()) {
...
String[]getALLLocalHostIP()
get ALL Local Host IP
String[] ipSet = null;
String hostName = getLocalHostName();
if (hostName.length() > 0) {
    try {
        InetAddress[] addresses = InetAddress.getAllByName(hostName);
        ipSet = new String[addresses.length];
        for (int i = 0; i < addresses.length; i++) {
            ipSet[i] = addresses[i].getHostAddress();
...
ListgetAllLocalIP()
get All Local IP
List<String> result = new ArrayList<String>();
Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
while (netInterfaces.hasMoreElements()) {
    NetworkInterface ni = netInterfaces.nextElement();
    Enumeration<InetAddress> ias = ni.getInetAddresses();
    while (ias.hasMoreElements()) {
        InetAddress ip = ias.nextElement();
        if (!ip.isLoopbackAddress() && (ip instanceof Inet4Address)) {
...
ListgetAllLocalIP()
get All Local IP
List<String> localServers = new ArrayList<String>();
String regExp = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
try {
    Enumeration<?> netInterfaces = NetworkInterface.getNetworkInterfaces();
    InetAddress ip = null;
    while (netInterfaces.hasMoreElements()) {
        NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
        Enumeration<?> address = ni.getInetAddresses();
...
CollectiongetAllLocalIPs()
Returns all available IP addresses.
final LinkedList<InetAddress> listAdr = new LinkedList<InetAddress>();
try {
    final Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
    if (nifs == null) {
        return listAdr;
    while (nifs.hasMoreElements()) {
        final NetworkInterface nif = nifs.nextElement();
...