当前位置: 首页>>代码示例>>Java>>正文


Java DhcpInfo类代码示例

本文整理汇总了Java中android.net.DhcpInfo的典型用法代码示例。如果您正苦于以下问题:Java DhcpInfo类的具体用法?Java DhcpInfo怎么用?Java DhcpInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DhcpInfo类属于android.net包,在下文中一共展示了DhcpInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDeviceSubnetMask

import android.net.DhcpInfo; //导入依赖的package包/类
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);
}
 
开发者ID:souliss,项目名称:soulissapp,代码行数:20,代码来源:NetUtils.java

示例2: serializeDhcpInfo

import android.net.DhcpInfo; //导入依赖的package包/类
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;
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:18,代码来源:JsonSerializer.java

示例3: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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);
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:18,代码来源:NetworkUtils.java

示例4: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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";
/*     */   }
 
开发者ID:zongyl,项目名称:smartLink,代码行数:21,代码来源:SnifferSmartLinker.java

示例5: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
@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;
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:17,代码来源:AndroidSystemServiceImpl.java

示例6: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:gerrylenz,项目名称:ESP8266-IOT-Android,代码行数:27,代码来源:mainActivity.java

示例7: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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";
}
 
开发者ID:davidvavra,项目名称:MoodSync,代码行数:17,代码来源:LFXNetworkUtils.java

示例8: wifiDhcpGatewayAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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;
    }
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:26,代码来源:GeckoNetworkManager.java

示例9: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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);
}
 
开发者ID:LorenK96,项目名称:slide-android,代码行数:19,代码来源:Broadcast.java

示例10: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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;
}
 
开发者ID:jmcgill,项目名称:lifx-alarm,代码行数:17,代码来源:LFXSocketGeneric.java

示例11: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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";
}
 
开发者ID:jmcgill,项目名称:lifx-alarm,代码行数:21,代码来源:LFXNetworkUtils.java

示例12: getWiFiBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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;
}
 
开发者ID:HobieCat,项目名称:drinviewer,代码行数:20,代码来源:DrinViewerBroadcastReceiver.java

示例13: getNetwork

import android.net.DhcpInfo; //导入依赖的package包/类
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);
}
 
开发者ID:EthACKdotOrg,项目名称:orWall,代码行数:22,代码来源:NetworkHelper.java

示例14: getBroadcastAddress

import android.net.DhcpInfo; //导入依赖的package包/类
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);
    }
}
 
开发者ID:timnew,项目名称:RemoteImagePicker,代码行数:21,代码来源:DiscoveryService.java

示例15: getConnectionInfo

import android.net.DhcpInfo; //导入依赖的package包/类
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;
}
 
开发者ID:eyalto,项目名称:wifiglue,代码行数:17,代码来源:WifiConnector.java


注:本文中的android.net.DhcpInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。