Java IP Address Get getInternalIp()

Here you can find the source of getInternalIp()

Description

get Internal Ip

License

Open Source License

Declaration

public static String getInternalIp() throws SocketException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

import java.net.Inet4Address;
import java.net.NetworkInterface;
import java.net.SocketException;

import java.util.Enumeration;

public class Main {
    public static String getInternalIp() throws SocketException {
        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()) {
                    return addr.getHostAddress();
                }/*from  w ww .  j av a2  s.c  om*/
            }
        }

        return null;
    }
}

Related

  1. getIniFileInputStreamEclipse()
  2. getInputStreamFromZipFile( String zipFilePath, String resourcePath)
  3. getInterfaceAddress(final String ifaceName, final boolean ipV4)
  4. getInterfaceIPs()
  5. getInternalIp()
  6. getInternetIpAddress()
  7. getIntfFromLabelAdva(int n, Inet4Address ip)
  8. getIntranetIp()
  9. getIP()