开发者

How can i get all the ip address of access points in the wifi ? Android

I am not able to get the IP address... Is it the right way to get the IP Address of all the access points by scanning through wifi ?

public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        List<ScanResult> results = wifiDemo.wifi.getScanResults();
        ScanResult bestSignal = null;
        for (ScanResult result : results) {


        }

        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 (!inet开发者_如何学GoAddress.isLoopbackAddress()) {
                        Toast.makeText(wifiDemo, TAG + "IP " + inetAddress.getHostAddress().toString(), Toast.LENGTH_LONG).show();
                    }
                }
            }
        } catch (SocketException e) {

            e.printStackTrace();
        }
    }


WiFi access points do not have IP addresses.


Did you try NetworkInterface.getNetworkInterfaces() approach to get all interfaces? and then iterate to get IP from each interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜