Java IP Address Get getLocalIpByInterfaceName(String interfaceName)

Here you can find the source of getLocalIpByInterfaceName(String interfaceName)

Description

get Local Ip By Interface Name

License

Apache License

Declaration

public static String getLocalIpByInterfaceName(String interfaceName) throws SocketException 

Method Source Code


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

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Main {
    public static String getLocalIpByInterfaceName(String interfaceName) throws SocketException {
        Enumeration<InetAddress> addressEnumeration = NetworkInterface.getByName(interfaceName).getInetAddresses();
        while (addressEnumeration.hasMoreElements()) {
            InetAddress address = addressEnumeration.nextElement();
            if (address instanceof Inet4Address) {
                return address.getHostAddress();
            }//from   ww w .  j  a  va  2s  . co  m
        }
        return null;
    }
}

Related

  1. getLocalIPAddress()
  2. getLocalIpAddress()
  3. getLocalIPAddresses()
  4. getLocalIPAddresses()
  5. getLocalIpAddresses()
  6. getLocalIPByNetworkInterface()
  7. getLocalIPCollection()
  8. getLocalIPList()
  9. getLocalIps()