Java IP Address Get getIPAddress(NetworkInterface e)

Here you can find the source of getIPAddress(NetworkInterface e)

Description

get IP Address

License

LGPL

Declaration

public static String getIPAddress(NetworkInterface e) 

Method Source Code


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

import java.net.InetAddress;
import java.net.NetworkInterface;

import java.util.Enumeration;

public class Main {
    public static String getIPAddress(NetworkInterface e) {
        Enumeration<InetAddress> a = e.getInetAddresses();
        for (; a.hasMoreElements();) {
            InetAddress addr = a.nextElement(); //IPv6 
            addr = a.nextElement(); //IPv4

            return addr.getHostAddress();

        }//from  w  w  w. ja  v  a 2 s  .  c  om

        return null;
    }
}

Related

  1. getIPAddress()
  2. getIpAddress()
  3. getIPAddress()
  4. getIPAddress(boolean useIPv4)
  5. getIPAddress(final String hostName)
  6. getIPAddress(String hostname)
  7. getIpAddress(String server)
  8. getIpAddresses()
  9. getIPAddresses()