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

StringgetIntranetIp()
get Intranet Ip
if (intranetIp == null) {
    try {
        intranetIp = InetAddress.getLocalHost().getHostAddress();
    } catch (Exception e) {
        intranetIp = "127.0.0.1";
return intranetIp;
...
InetAddressgetIP()
Get an IP.
if (_ip != null) {
    return _ip;
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
NetworkInterface ni;
while (nis.hasMoreElements()) {
    ni = nis.nextElement();
    if (!ni.isLoopback() && ni.isUp()) {
...
StringgetIp()
get Ip
if (null != cachedIpAddress) {
    return cachedIpAddress;
Enumeration<NetworkInterface> netInterfaces;
try {
    netInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (final SocketException ex) {
    return "unknown ip";
...
byte[]getIP()
get IP
try {
    Enumeration allNetInterfaces = NetworkInterface.getNetworkInterfaces();
    InetAddress ip = null;
    byte[] internalIP = null;
    while (allNetInterfaces.hasMoreElements()) {
        NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
        Enumeration addresses = netInterface.getInetAddresses();
        while (addresses.hasMoreElements()) {
...
StringgetIp()
Gets my IP as String.
try {
    List<String> ips = new ArrayList<String>();
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface current = interfaces.nextElement();
        if (current.isUp() && !current.isLoopback() && !current.isVirtual()) {
            Enumeration<InetAddress> addresses = current.getInetAddresses();
            while (addresses.hasMoreElements()) {
...
StringgetIp()
get Ip
String ip = null;
try {
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface iface = interfaces.nextElement();
        if (iface.isLoopback() || !iface.isUp())
            continue;
        Enumeration<InetAddress> addresses = iface.getInetAddresses();
...
StringgetIp()
Checks public IP address from Amazon's API
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = null;
try {
    in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
    String ip = in.readLine();
    return ip;
} finally {
    if (in != null) {
...
StringgetIp()
get Ip
if (ipAddress == null) {
    try {
        URL whatismyip = new URL("http://checkip.amazonaws.com");
        try (BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()))) {
            ipAddress = in.readLine();
    } catch (Throwable e) {
        System.err.println("Unable to retrieve this machine's external ip: " + e.getMessage());
...
StringgetIp()
get Ip
InetAddress ip;
try {
    ip = InetAddress.getLocalHost();
    return ip.getHostAddress();
} catch (UnknownHostException e) {
    e.printStackTrace();
return "localhost";
...
StringgetIP()
get IP
String ip = "";
try {
    Enumeration<?> e1 = (Enumeration<?>) NetworkInterface.getNetworkInterfaces();
    while (e1.hasMoreElements()) {
        NetworkInterface ni = (NetworkInterface) e1.nextElement();
        if (!ni.getName().equals("eth0")) {
            continue;
        } else {
...