get Wifi Ap Ip Address - Android android.net.wifi

Android examples for android.net.wifi:Wifi Address

Description

get Wifi Ap Ip Address

Demo Code

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Main {

  public static String getWifiApIpAddress() {
    try {/*ww  w  .j  av a 2s . c o  m*/
      for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
        NetworkInterface intf = en.nextElement();
        if (intf.getName().contains("wlan")) {
          for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
            InetAddress inetAddress = enumIpAddr.nextElement();
            if (!inetAddress.isLoopbackAddress() && (inetAddress.getAddress().length == 4)) {
              return inetAddress.getHostAddress();
            }
          }
        }
      }
    } catch (SocketException e) {
      e.printStackTrace();
    }

    return null;
  }

}

Related Tutorials