Here you can find the source of getIpAddress()
public static String getIpAddress()
//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; } }