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.Socket;

public class Main {
    public static String getIpAddress() {
        String ipAddress = "";
        try {//from w  w  w . j a  v a2  s .  c  o m
            Socket socket = new Socket("google.com", 80);
            InetAddress inetAddress = socket.getLocalAddress();
            if (inetAddress != null) {
                ipAddress = inetAddress.getHostAddress();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ipAddress;
    }
}

Related

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