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

ListgetLocalIPs()
get Local I Ps
Enumeration<NetworkInterface> interfaces;
try {
    interfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
    return null;
List<InetAddress> ips = new ArrayList<InetAddress>();
while (interfaces.hasMoreElements()) {
...
ArrayListgetLocalIPs()
Returns the list of local IP numbers.
ArrayList<String> ips = new ArrayList<String>();
Enumeration<NetworkInterface> netcards = NetworkInterface.getNetworkInterfaces();
while (netcards.hasMoreElements()) {
    Enumeration<InetAddress> inets = netcards.nextElement().getInetAddresses();
    while (inets.hasMoreElements()) {
        InetAddress inet = inets.nextElement();
        String addr = inet.getHostAddress();
        ips.add(addr);
...
ListgetLocalIPs(boolean refresh)
get Local I Ps
if (isCacheEnabled && isCacheValid && !refresh) {
    return new ArrayList<String>(cachedLocalIPs);
List<String> result = new ArrayList();
try {
    Enumeration<NetworkInterface> eNics = NetworkInterface.getNetworkInterfaces();
    while (eNics.hasMoreElements()) {
        NetworkInterface nic = eNics.nextElement();
...
ListgetLocalIpv4()
get Local Ipv
try {
    List<String> ips = new ArrayList<String>();
    for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces
            .hasMoreElements();) {
        NetworkInterface networkInterface = interfaces.nextElement();
        if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
            continue;
        Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
        if (addresses.hasMoreElements()) {
            InetAddress nextElement = addresses.nextElement();
            if (nextElement instanceof Inet4Address) {
                ips.add(nextElement.getHostAddress());
    return ips;
} catch (SocketException e) {
    throw new RuntimeException(e.getMessage(), e);
StringgetLocalIPv6Address()
get Local I Pv Address
InetAddress inetAddress = null;
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
outer: while (networkInterfaces.hasMoreElements()) {
    Enumeration<InetAddress> inetAds = networkInterfaces.nextElement().getInetAddresses();
    while (inetAds.hasMoreElements()) {
        inetAddress = inetAds.nextElement();
        if (inetAddress instanceof Inet6Address && !isReservedAddr(inetAddress)) {
            break outer;
...
StringgetLocalNetWorkIp()
get Local Net Work Ip
if (localIp != null) {
    return localIp;
try {
    Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
    InetAddress ip = null;
    while (netInterfaces.hasMoreElements()) {
        NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
...
StringgetLocalV4Ip()
get Local V Ip
try {
    InetAddress localHost = InetAddress.getLocalHost();
    String localIp = localHost.getHostAddress();
    if (validationIpV4FormatAddress(localIp)) {
        return localIp;
} catch (UnknownHostException ignore) {
return LOOPBACK_ADDRESS_V4;
ListgetLocalV4IpList()
Returns a list of ip addreses on this machine that is accessible from a remote source.
List<String> result = new ArrayList<String>();
Enumeration<NetworkInterface> interfaces = null;
try {
    interfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException ignore) {
if (interfaces == null) {
    return Collections.EMPTY_LIST;
...
longgetLongIp(byte[] buff)
get Long Ip
long ip;
long workLong1, workLong2, workLong3, workLong4;
workLong1 = (long) buff[0] & 0x000000FF;
workLong1 = workLong1 << 24;
workLong2 = (long) buff[1] & 0x000000FF;
workLong2 = workLong2 << 16;
workLong3 = (long) buff[2] & 0x000000FF;
workLong3 = workLong3 << 8;
...
LonggetLongIp(String ipString)
Convert Ip from String to Long.
if (ipString == null) {
    throw new IllegalArgumentException("null input");
InetAddress ip;
try {
    ip = InetAddress.getByName(ipString);
} catch (Exception e) {
    throw new IllegalArgumentException("Ip is not valid" + ipString);
...