Java IP Address Get getIpAddress()

Here you can find the source of getIpAddress()

Description

get Ip Address

License

Open Source License

Declaration

public static String getIpAddress() 

Method Source Code

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

import java.net.InetAddress;

import java.net.URL;

public class Main {
    public static String getIpAddress() {
        try {/*from   ww w  . j a  v  a 2 s  .  co m*/
            return InetAddress.getLocalHost().getHostAddress();
        } catch (Exception ex) {
        }
        return null;
    }

    public static String getIpAddress(String url) {
        if (url == null || url.isEmpty()) {
            throw new IllegalArgumentException("URL cannot be null or empty!");
        }
        try {
            return InetAddress.getByName(new URL(url).getHost()).getHostAddress();
        } catch (Exception ex) {
            throw new IllegalStateException("Cannot get IP address of " + url + "!\n");
        }
    }
}

Related

  1. getIPAddress()
  2. getIPAddress()
  3. getIpAddress()
  4. getIpAddress()
  5. getIPAddress()
  6. getIPAddress()
  7. getIpAddress()
  8. getIpAddress()
  9. getIPAddress()