Java examples for Network:IP Address
get Local Host IP
//package com.java2s; import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getLocalHostIP()); }//w w w . ja va 2s. co m public static String getLocalHostIP() { try { InetAddress addr = InetAddress.getLocalHost(); return addr.getHostAddress(); } catch (UnknownHostException e) { throw new RuntimeException( "it can't get local host ip error as :", e); } } }