Here you can find the source of getIp()
public static String getIp()
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static String getIp() { InetAddress ip;//from w w w.j av a2 s . co m try { ip = InetAddress.getLocalHost(); return ip.getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); } return "localhost"; } }