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


Java WifiManager.getDhcpInfo方法代码示例

本文整理汇总了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);
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:18,代码来源:NetworkUtils.java

示例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)
    );
}
 
开发者ID:voroshkov,项目名称:Chorus-RF-Laptimer,代码行数:14,代码来源:MainActivity.java

示例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);
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:9,代码来源:WifiTool.java

示例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);

}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:29,代码来源:NetworkUtils.java


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