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

StringgetLocalIp()
get Local Ip
String ret = null;
try {
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    while (nets.hasMoreElements()) {
        NetworkInterface net = nets.nextElement();
        if (net.isLoopback() || net.isVirtual() || net.getName().startsWith("vmnet")
                || net.getName().startsWith("docker")) {
            continue;
...
StringgetLocalIp()
Returns the local IP.
return chooseAddress().getHostAddress();
StringgetLocalIP()
get Local IP
if (localIp != null) {
    return localIp;
Enumeration<?> e1 = (Enumeration<?>) NetworkInterface.getNetworkInterfaces();
while (e1.hasMoreElements()) {
    NetworkInterface ni = (NetworkInterface) e1.nextElement();
    if (!isUp(ni)) {
        continue;
...
StringgetLocalIP()
get Local IP
String localip = "";
InetAddress inetaddress = InetAddress.getLocalHost();
localip = inetaddress.getHostAddress();
if ("127.0.0.1".equals(localip) || "localhost".equals(localip) || localip.indexOf("local") != -1) {
    Enumeration<NetworkInterface> allnetinterface = NetworkInterface.getNetworkInterfaces();
    while (allnetinterface.hasMoreElements()) {
        NetworkInterface net = allnetinterface.nextElement();
        Enumeration<InetAddress> ipenum = net.getInetAddresses();
...
int[]getLocalIP()
get Local IP
try {
    InetAddress addr = InetAddress.getLocalHost();
    byte[] ip = addr.getAddress();
    if (ip == null || ip.length != 4) {
        return null;
    int[] ret = new int[4];
    for (int cnt = 0; cnt < 4; cnt++) {
...
StringgetLocalIP()
get Local IP
return getLocalIP(EXCLUDE_IP);
StringgetLocalIp()
get Local Ip
try {
    Pattern pattern = Pattern.compile("(172|10)\\.[0-9]+\\.[0-9]+\\.[0-9]+");
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
    while (interfaces.hasMoreElements()) {
        NetworkInterface ni = interfaces.nextElement();
        Enumeration<InetAddress> en = ni.getInetAddresses();
        while (en.hasMoreElements()) {
            InetAddress addr = en.nextElement();
...
StringgetLocalIp()
get Local Ip
return getLocalIp("*>10>172>192>127");
InetAddressgetLocalIP()
Get a local IP for remote access.
Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
InetAddress localip = null;
while (netInterfaces.hasMoreElements()) {
    NetworkInterface netIntf = netInterfaces.nextElement();
    Enumeration<InetAddress> address = netIntf.getInetAddresses();
    while (address.hasMoreElements()) {
        ip = address.nextElement();
...
StringgetLocalIp()
Get local IP
String ip = InetAddress.getLocalHost().getHostAddress();
return ip;