Java Utililty Methods Local Address Get

List of utility methods to do Local Address Get

Description

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

Method

InetAddressgetLocalAddress()
from: http://www.java2s.com/Code/Java/Network-Protocol/FindsalocalnonloopbackIPv4address.htm Finds a local, non-loopback, IPv4 address
try {
    Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
    while (ifaces.hasMoreElements()) {
        NetworkInterface iface = ifaces.nextElement();
        Enumeration<InetAddress> addresses = iface.getInetAddresses();
        while (addresses.hasMoreElements()) {
            InetAddress addr = addresses.nextElement();
            if (addr instanceof Inet4Address && !addr.isLoopbackAddress()) {
...
byte[]getLocalAddress()
get Local Address
if (localAddress == null) {
    try {
        InetAddress inetAddress = InetAddress.getLocalHost();
        localAddress = inetAddress.getAddress();
    } catch (Exception e) {
return localAddress;
...
InetAddressgetLocalAddress()
Get the IP Address by which the rest of the world knows us.
if (localAddress != null) {
    return localAddress;
InetAddress addr = null;
try {
    addr = InetAddress.getByName(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
    addr = null;
...
InetAddressgetLocalAddress()
get Local Address
if (localInetAddress_ == null)
    localInetAddress_ = InetAddress.getLocalHost();
return localInetAddress_;
StringgetLocalAddress()
Gets the local address.
Enumeration<NetworkInterface> allNetInterfaces;
try {
    allNetInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
    e.printStackTrace();
    return "NO";
InetAddress ip = null;
...
InetAddressgetLocalAddress()
Look for a usable network interface address to use for tests.
return InetAddress.getByName("127.0.0.1");
InetAddressgetLocalAddress()
get Local Address
InetAddress localAddress = null;
try {
    localAddress = InetAddress.getLocalHost();
    if (isValidAddress(localAddress)) {
        return localAddress;
} catch (Throwable e) {
    e.printStackTrace();
...
InetAddressgetLocalAddress()
Get a local, IP4 Address, preferable a non-loopback address which is bound to an interface.
InetAddress addr = InetAddress.getLocalHost();
NetworkInterface nif = NetworkInterface.getByInetAddress(addr);
if (addr.isLoopbackAddress() || addr instanceof Inet6Address || nif == null) {
    InetAddress lookedUpAddr = findLocalAddressViaNetworkInterface();
    addr = lookedUpAddr != null ? lookedUpAddr : InetAddress.getByName("127.0.0.1");
return addr;
StringgetLocalAddress()
get Local Address
InetAddress inetAddress = null;
try {
    inetAddress = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
    e.printStackTrace();
return inetAddress.getHostAddress();
InetAddressgetLocalAddress()
get Local Address
try {
    final InetAddress addr = InetAddress.getLocalHost();
    return addr;
} catch (UnknownHostException e) {
    try {
        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
        if (interfaces == null) {
            return null;
...