get Wifi Broadcast Ip - Android Phone

Android examples for Phone:wifi

Description

get Wifi Broadcast Ip

Demo Code


import java.util.List;
import android.net.DhcpInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.util.Log;

public class Main{
    private static WifiManager mWifiManager;
    public static String getBroadcastIp() {
        DhcpInfo dinfo = mWifiManager.getDhcpInfo();
        int ip = changeEndian(dinfo.gateway);
        if (Config.DEBUG)
        return StrOfLongIP(ip + 254);
    }//w ww  .j a va2s . com
    public static int changeEndian(int s) {
        int dest = 0;
        dest = ((s & 0x00ff00ff) << 8) + ((s & 0xff00ff00) >>> 8);
        dest = ((dest & 0x0000ffff) << 16) + ((dest & 0xffff0000) >>> 16);
        return dest;
    }
    private static String StrOfLongIP(int longIP) {
        return String.valueOf(longIP >>> 24) + "."
                + String.valueOf((longIP & 0x00FFFFFF) >>> 16) + "."
                + String.valueOf((longIP & 0x0000FFFF) >>> 8) + "."
                + String.valueOf(longIP & 0x000000FF);
    }
}

Related Tutorials