Android examples for Network:IP Address
get Host Ip
//package com.java2s; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; public class Main { public static String getHostIp() { try {/*www . j a v a2s.c o m*/ Enumeration<NetworkInterface> en = NetworkInterface .getNetworkInterfaces(); while (null != en && en.hasMoreElements()) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> ipAddr = intf .getInetAddresses(); ipAddr.hasMoreElements();) { InetAddress inetAddress = ipAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress(); } } } } catch (Exception e) { e.printStackTrace(); } return null; } }