Java 类android.net.DhcpInfo 实例源码

项目:mobly-bundled-snippets    文件:JsonSerializer.java   
private JSONObject serializeDhcpInfo(DhcpInfo data) throws JSONException {
    JSONObject result = new JSONObject(mGson.toJson(data));
    int ipAddress = data.ipAddress;
    byte[] addressBytes = {
        (byte) (0xff & ipAddress),
        (byte) (0xff & (ipAddress >> 8)),
        (byte) (0xff & (ipAddress >> 16)),
        (byte) (0xff & (ipAddress >> 24))
    };
    try {
        String addressString = InetAddress.getByAddress(addressBytes).toString();
        result.put("IpAddress", addressString);
    } catch (UnknownHostException e) {
        result.put("IpAddress", ipAddress);
    }
    return result;
}
项目:phonk    文件:NetworkUtils.java   
public static InetAddress getBroadcastAddress(Context c) throws UnknownHostException {
    WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();

    if (dhcp == null) {
        return InetAddress.getByAddress(null);
    }

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;

    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++) {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }

    return InetAddress.getByAddress(quads);
}
项目:smartLink    文件:SnifferSmartLinker.java   
private String getBroadcastAddress(Context ctx)
/*     */   {
/* 109 */     WifiManager cm = (WifiManager)ctx
/* 110 */       .getSystemService("wifi");
/* 111 */     DhcpInfo myDhcpInfo = cm.getDhcpInfo();
/* 112 */     if (myDhcpInfo == null) {
/* 113 */       return "255.255.255.255";
/*     */     }
/*     */     
/*     */ 
/* 117 */     int broadcast = myDhcpInfo.ipAddress & myDhcpInfo.netmask | 
/* 118 */       myDhcpInfo.netmask ^ 0xFFFFFFFF;
/* 119 */     byte[] quads = new byte[4];
/* 120 */     for (int k = 0; k < 4; k++)
/* 121 */       quads[k] = ((byte)(broadcast >> k * 8 & 0xFF));
/*     */     try {
/* 123 */       return InetAddress.getByAddress(quads).getHostAddress();
/*     */     } catch (Exception e) {}
/* 125 */     return "255.255.255.255";
/*     */   }
项目:LuoYing    文件:AndroidSystemServiceImpl.java   
@Override
public InetAddress getBroadcastAddress() {
    try {
        WifiManager wifi = (WifiManager) Global.getContext().getSystemService(Context.WIFI_SERVICE);
        DhcpInfo dhcp = wifi.getDhcpInfo();
        int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
        byte[] quads = new byte[4];
        for (int k = 0; k < 4; k++) {
            quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
        }
        return InetAddress.getByAddress(quads);
    } catch (UnknownHostException ex) {
        Log.e(AndroidSystemServiceImpl.class.getName(), "Could not getBroadcastAddress!", ex);
    }
    return null;
}
项目:ESP8266-IOT-Android    文件:mainActivity.java   
/**
 * Calculate the broadcast IP we need to send the packet along. If we send it
 * to 255.255.255.255, it never gets sent. I guess this has something to do
 * with the mobile network not wanting to do broadcast.
 */
private InetAddress getBroadcastAddress() throws IOException {
    Log.i(TAG, "Entree getBroadcastAddress");

    WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
    DhcpInfo dhcp = wm.getDhcpInfo();

    if (dhcp == null) {
        Log.d(TAG, "Could not get dhcp info");
        return null;
    }

    Log.d(TAG, "ipAddress::" + BigInteger.valueOf(wm.getDhcpInfo().netmask).toString());

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);

    Log.d(TAG, "BroadcastAddress:" + getByAddress(quads).getHostAddress());
    return getByAddress(quads);
}
项目:MoodSync    文件:LFXNetworkUtils.java   
public static String getBroadcastAddress(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) (broadcast >> (k * 8));
    try {
        return InetAddress.getByAddress(quads).getHostAddress();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

    return "255.255.255.255";
}
项目:soulissapp    文件:NetUtils.java   
public static InetAddress getDeviceSubnetMask(Context ctx) {
    WifiManager wifii = (WifiManager) ctx.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    DhcpInfo d = wifii.getDhcpInfo();
    //A volte non funziona e torna 0.
    if (d.netmask == 0) {
        InetAddress localHost = null;
        try {
            NetworkInterface networkInterface = NetworkInterface.getByInetAddress(NetUtils.intToInet(d.ipAddress));
            //get(1) e` IP4
            byte[] subDario = subnetLenghtToSubnetAddressDario(networkInterface.getInterfaceAddresses().get(1).getNetworkPrefixLength());
            Log.w(Constants.TAG, "Emergency subnet recovery from IP Address mask lenght:" + networkInterface.getInterfaceAddresses().get(1).getNetworkPrefixLength());
            return Inet4Address.getByAddress(subDario);
        } catch (Exception e) {
            Log.e(Constants.TAG, "Errore nel recupero subnet mask per: " + d.ipAddress);
            e.printStackTrace();
        }
    }
    return intToInet(d.netmask);
}
项目:mc_backup    文件:GeckoNetworkManager.java   
private int wifiDhcpGatewayAddress() {
    if (mConnectionType != ConnectionType.WIFI) {
        return 0;
    }

    if (null == mApplicationContext) {
        return 0;
    }

    try {
        WifiManager mgr = (WifiManager) mApplicationContext.getSystemService(Context.WIFI_SERVICE);
        DhcpInfo d = mgr.getDhcpInfo();
        if (d == null) {
            return 0;
        }

        return d.gateway;

    } catch (Exception ex) {
        // getDhcpInfo() is not documented to require any permissions, but on some devices
        // requires android.permission.ACCESS_WIFI_STATE. Just catch the generic exception
        // here and returning 0. Not logging because this could be noisy.
        return 0;
    }
}
项目:slide-android    文件:Broadcast.java   
private InetAddress getBroadcastAddress()
    throws UnknownHostException
{
    final WifiManager wifi = (WifiManager) SettingsActivity.getActivity().getSystemService(
        Context.WIFI_SERVICE);
    final DhcpInfo dhcp = wifi.getDhcpInfo();
    if (dhcp == null)
    {
        return InetAddress.getByName("0.0.0.0");
    }
    final int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    final byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
    {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }
    return InetAddress.getByAddress(quads);
}
项目:lifx-alarm    文件:LFXSocketGeneric.java   
public final static byte[] getBroadcastAddress( Context context)
{
    WifiManager wifi = (WifiManager) context.getSystemService( Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    // handle null somehow

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4]; 

    for( int k = 0; k < 4; k++)
    {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }

    return quads;
}
项目:lifx-alarm    文件:LFXNetworkUtils.java   
public static String getBroadcastAddress( Context context)
{
    WifiManager wifi = (WifiManager) context.getSystemService( Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
      quads[k] = (byte) (broadcast >> (k * 8));
    try
    {
        return InetAddress.getByAddress(quads).getHostAddress();
    } 
    catch( UnknownHostException e)
    {
        e.printStackTrace();
    }

    return "255.255.255.255";
}
项目:drinviewer    文件:DrinViewerBroadcastReceiver.java   
private String getWiFiBroadcastAddress (Context context) {
    String bcastaddr = null;
    WifiManager mWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
       DhcpInfo dhcp = mWifi.getDhcpInfo();

    if (mWifi.isWifiEnabled() && dhcp != null) {
        int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
        byte[] quads = new byte[4];
        for (int k = 0; k < 4; k++)
            quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);

        try {
            bcastaddr = InetAddress.getByAddress(quads).getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
    return bcastaddr;
}
项目:PebbLIFX    文件:LFXSocketGeneric.java   
public final static byte[] getBroadcastAddress( Context context)
{
    WifiManager wifi = (WifiManager) context.getSystemService( Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    // handle null somehow

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4]; 

    for( int k = 0; k < 4; k++)
    {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }

    return quads;
}
项目:PebbLIFX    文件:LFXNetworkUtils.java   
public static String getBroadcastAddress( Context context)
{
    WifiManager wifi = (WifiManager) context.getSystemService( Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
      quads[k] = (byte) (broadcast >> (k * 8));
    try
    {
        return InetAddress.getByAddress(quads).getHostAddress();
    } 
    catch( UnknownHostException e)
    {
        e.printStackTrace();
    }

    return "255.255.255.255";
}
项目:orWall    文件:NetworkHelper.java   
private static String getNetwork(DhcpInfo dhcp){
    int ip = dhcp.ipAddress;
    int mask = dhcp.netmask;
    if (ip == 0 || mask == 0) return null;

    if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
        ip = Integer.reverseBytes(ip);
        mask = Integer.reverseBytes(mask);
    }

    ip &= mask;
    mask = netmaskToCIDR(mask);
    if (mask == 0) return null;

    int a = (ip >> 24) & 0xFF;
    int b = (ip >> 16) & 0xFF;
    int c = (ip >>  8) & 0xFF;
    int d = ip & 0xFF;

    return String.format(Locale.US, "%d.%d.%d.%d/%d", a, b, c, d, mask);
}
项目:RemoteImagePicker    文件:DiscoveryService.java   
private InetAddress getBroadcastAddress() {
    DhcpInfo dhcp = wifiManager.getDhcpInfo();

    if (dhcp == null) {
        Log.d(TAG, "Could not get dhcp info");
        return null;
    }

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);

    try {
        return InetAddress.getByAddress(quads);
    } catch (UnknownHostException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
项目:wifiglue    文件:WifiConnector.java   
public ConnectionInfo getConnectionInfo() {
  ConnectionInfo info = new ConnectionInfo();
  WifiInfo winf = mWifiMgr.getConnectionInfo();
  info.winf = winf;

  if (winf != null) {
    if (winf.getSSID() != null) {
      String winfSsid = unQuote(winf.getSSID());
      if (winfSsid.equals(mNetssid)) {
        DhcpInfo dhinf = mWifiMgr.getDhcpInfo();
        info.dhinf = dhinf;
      }
    }
  }
  return info;
}
项目:Chorus-RF-Laptimer    文件:MainActivity.java   
private String getGatewayIP() {
    if (!checkIsWifiOnAndConnected()) return "0.0.0.0";

    WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    int ip = dhcp.gateway;
    return String.format("%d.%d.%d.%d",
        (ip & 0xff),
        (ip >> 8 & 0xff),
        (ip >> 16 & 0xff),
        (ip >> 24 & 0xff)
    );
}
项目:mobly-bundled-snippets    文件:JsonSerializer.java   
public JSONObject toJson(Object object) throws JSONException {
    if (object instanceof DhcpInfo) {
        return serializeDhcpInfo((DhcpInfo) object);
    } else if (object instanceof WifiConfiguration) {
        return serializeWifiConfiguration((WifiConfiguration) object);
    } else if (object instanceof WifiInfo) {
        return serializeWifiInfo((WifiInfo) object);
    }
    return defaultSerialization(object);
}
项目:Auto.js    文件:WifiTool.java   
public static String getRouterIp(Context context){
    WifiManager wifiService = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if(wifiService == null){
        return null;
    }
    DhcpInfo dhcpInfo = wifiService.getDhcpInfo();
    return Formatter.formatIpAddress(dhcpInfo.gateway);
}
项目:cordova-plugin-wifiinfo    文件:WifiInfo.java   
private static JSONObject jsonifyDhcpInfo(DhcpInfo info) throws JSONException {
    JSONObject obj = new JSONObject();

    obj.put("dns1", ipToString(info.dns1) );
    obj.put("dns2", ipToString(info.dns2) );
    obj.put("gateway", ipToString(info.gateway) );
    obj.put("ip", ipToString(info.ipAddress) );
    obj.put("lease", info.leaseDuration );
    obj.put("netmask", ipToString(info.netmask) );
    obj.put("server", ipToString(info.serverAddress) );

    return obj;
}
项目:TPlayer    文件:WifiManagerStub.java   
private DhcpInfo createDhcpInfo(IPInfo ip) {
    DhcpInfo i = new DhcpInfo();
    i.ipAddress = ip.ip_hex;
    i.netmask = ip.netmask_hex;
    i.dns1 = 0x04040404;
    i.dns2 = 0x08080808;
    return i;
}
项目:phonk    文件:NetworkUtils.java   
public static void getGatewayIpAddress(Context c) {
    // get wifi ip

    final WifiManager manager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    final DhcpInfo dhcp = manager.getDhcpInfo();
    final String address = Formatter.formatIpAddress(dhcp.gateway);

    StringBuilder IFCONFIG = new StringBuilder();
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress()
                        && inetAddress.isSiteLocalAddress()) {
                    IFCONFIG.append(inetAddress.getHostAddress().toString() + "\n");
                }

            }
        }
    } catch (SocketException ex) {
        Log.e("LOG_TAG", ex.toString());
    }
    MLog.d(TAG, "ifconfig " + IFCONFIG.toString());

    MLog.d(TAG, "hotspot address is " + address);

}
项目:ssj    文件:Util.java   
public static InetAddress getBroadcastAddress() throws IOException {
    WifiManager wifi = (WifiManager)SSJApplication.getAppContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    if(dhcp == null)
        throw new IOException("dhcp is null");

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    return InetAddress.getByAddress(quads);
}
项目:empeg-remote    文件:Discoverer.java   
/**
 * Calculate the broadcast IP we need to send the packet along. If we send it
 * to 255.255.255.255, it never gets sent. I guess this has something to do
 * with the mobile network not wanting to do broadcast.
 */
private InetAddress getBroadcastAddress() throws IOException {
    DhcpInfo dhcp = mWifi.getDhcpInfo();
    if (dhcp == null) {
        //Log.d("InetAddress getBroadcastAddress()", "Could not get dhcp info");
        return null;
    }

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    return InetAddress.getByAddress(quads);
}
项目:lifx-sdk-android    文件:LFXSocketGeneric.java   
public static byte[] getBroadcastAddress(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    // handle null somehow

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];

    for (int k = 0; k < 4; k++) {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }

    return quads;
}
项目:lifx-sdk-android    文件:LFXNetworkUtils.java   
public static String getBroadcastAddress(Context context) {
    if (sBroadcastAddress != null && sBroadcastAddressExpires > System.currentTimeMillis()) {
        return sBroadcastAddress;
    }

    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    if (wifi != null) {
        DhcpInfo dhcp = wifi.getDhcpInfo();

        if (dhcp != null) {
            int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
            byte[] quads = new byte[4];
            for (int k = 0; k < 4; k++)
                quads[k] = (byte) (broadcast >> (k * 8));
            try {
                sBroadcastAddress = InetAddress.getByAddress(quads).getHostAddress();
                sBroadcastAddressExpires = System.currentTimeMillis() + EXPIRE_TIME;
                return sBroadcastAddress;
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
        }
    }

    sBroadcastAddress = "255.255.255.255";
    sBroadcastAddressExpires = System.currentTimeMillis() + EXPIRE_TIME;
    return sBroadcastAddress;
}
项目:reboot-router    文件:Utils.java   
/**
 * Returns the Gateway IP of current network.
 */
public static String refreshGateway(Context context) {
    WifiManager wifiManager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
    return Utils.parseIp(dhcpInfo.gateway);
}
项目:FZBaseLib    文件:FZNetworkInfoHelper.java   
/**
 * 获取设备IP地址
 *
 * @param context 上下文
 * @return IP地址
 */
public static String getDeviceIpAddress(Context context) {
    String ipAddress = "UNKNOWN";
    if (isNetworkAvailable(context)) {
        WifiManager wifiInfo = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        DhcpInfo d = wifiInfo.getDhcpInfo();
        if (d != null) {
            ipAddress = String.valueOf(d.ipAddress);
        }
    }
    return ipAddress;
}
项目:faims-android    文件:ServerDiscovery.java   
private String getIPAddress() throws IOException {
WifiManager wifiManager = (WifiManager) FAIMSApplication.getInstance().getApplication().getSystemService(Application.WIFI_SERVICE);
    DhcpInfo myDhcpInfo = wifiManager.getDhcpInfo();
    if (myDhcpInfo == null) {
        FLog.d("could not determine device ip");
        return null;
    }
    int broadcast = myDhcpInfo.ipAddress;
byte[] quads = new byte[4];
for (int k = 0; k < 4; k++)
quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
return InetAddress.getByAddress(quads).getHostAddress();
  }
项目:lib_zkc_printer_driver    文件:TcpClientClass.java   
@SuppressWarnings({ "unused", "deprecation" })
public String getGatewayIPAddress(Context ctx) {
    WifiManager wifi_service = (WifiManager) ctx
            .getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcpInfo = wifi_service.getDhcpInfo();
    WifiInfo wifiinfo = wifi_service.getConnectionInfo();
    return Formatter.formatIpAddress(dhcpInfo.gateway);
}
项目:MoodSync    文件:LFXSocketGeneric.java   
public final static byte[] getBroadcastAddress(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    // handle null somehow

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];

    for (int k = 0; k < 4; k++) {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }

    return quads;
}
项目:rokontrol-android    文件:SSDPSocket.java   
private InetAddress getBroadcastAddress() throws IOException {
    WifiManager wifi = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    // handle null somehow

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    return InetAddress.getByAddress(quads);
}
项目:mythmote    文件:WOLPowerManager.java   
/**
 * Returns the IP broadcast address for the current wifi connection
 * @param mContext
 * @return
 * @throws IOException
 */
private static InetAddress getBroadcastAddress(final Context mContext) throws IOException
{
    WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++){
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }
    return InetAddress.getByAddress(quads);
}
项目:AndroidCourses    文件:WifiUtils.java   
public static byte[] getBroadcastIPAddressRaw(final Context pContext) throws WifiUtilsException {
    final WifiManager wifiManager = WifiUtils.getWifiManager(pContext);
    final DhcpInfo dhcp = wifiManager.getDhcpInfo();
    // TODO handle null somehow...

    final int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    final byte[] broadcastIP = new byte[IPUtils.IPV4_LENGTH];
    for (int k = 0; k < IPUtils.IPV4_LENGTH; k++) {
        broadcastIP[k] = (byte) ((broadcast >> (k * 8)) & 0xFF);
    }
    return broadcastIP;
}
项目:AndroidCourses    文件:WifiUtils.java   
public static byte[] getBroadcastIPAddressRaw(final Context pContext) throws WifiUtilsException {
    final WifiManager wifiManager = WifiUtils.getWifiManager(pContext);
    final DhcpInfo dhcp = wifiManager.getDhcpInfo();
    // TODO handle null somehow...

    final int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    final byte[] broadcastIP = new byte[IPUtils.IPV4_LENGTH];
    for (int k = 0; k < IPUtils.IPV4_LENGTH; k++) {
        broadcastIP[k] = (byte) ((broadcast >> (k * 8)) & 0xFF);
    }
    return broadcastIP;
}
项目:IOT-Espressif-Android    文件:SSSActionDeviceUpgradeLocal.java   
@Override
public String getGatewayAddr(Context context)
{
    WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo d = wm.getDhcpInfo();
    return __formatString(d.gateway);
}
项目:tilt-game-android    文件:WifiUtils.java   
public static byte[] getBroadcastIPAddressRaw(final Context pContext) throws WifiUtilsException {
    final WifiManager wifiManager = WifiUtils.getWifiManager(pContext);
    final DhcpInfo dhcp = wifiManager.getDhcpInfo();
    // TODO handle null somehow...

    final int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    final byte[] broadcastIP = new byte[IPUtils.IPV4_LENGTH];
    for (int k = 0; k < IPUtils.IPV4_LENGTH; k++) {
        broadcastIP[k] = (byte) ((broadcast >> (k * 8)) & 0xFF);
    }
    return broadcastIP;
}
项目:EspLight-APP    文件:MainActivity.java   
InetAddress getBroadcastAddress() throws IOException {
    Context mContext=getApplicationContext();
    WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    // handle null somehow

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    return InetAddress.getByAddress(quads);
}
项目:Android-Wake-On-Lan    文件:WOLService.java   
private InetAddress getBroadcastAddress() throws IOException {
    DhcpInfo dhcp = wifiManager.getDhcpInfo();
    // handle null somehow

    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++)
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    return InetAddress.getByAddress(quads);
}