本文整理汇总了Java中android.net.wifi.WifiManager.getDhcpInfo方法的典型用法代码示例。如果您正苦于以下问题:Java WifiManager.getDhcpInfo方法的具体用法?Java WifiManager.getDhcpInfo怎么用?Java WifiManager.getDhcpInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.wifi.WifiManager
的用法示例。
在下文中一共展示了WifiManager.getDhcpInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBroadcastAddress
import android.net.wifi.WifiManager; //导入方法依赖的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);
}
示例2: getGatewayIP
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
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)
);
}
示例3: getRouterIp
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
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);
}
示例4: getGatewayIpAddress
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
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);
}