本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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";
/* */ }
示例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;
}
示例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);
}
示例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";
}
示例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;
}
}
示例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);
}
示例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;
}
示例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";
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}