将路由器ipv4地址添加到Android设备

时间:2015-08-19 16:37:44

标签: android connection ip wifi ipv4

我需要将路由器ipv4 address添加到我的Android手机中。有可能吗?从计算机上获取ipv4很容易我需要输入ipconfigcmd enter image description here

但如何从Android设备获取已经连接的路由器ipv4?这是我连接到路由器的安卓代码

 @Override
    public void onReceive(Context context, Intent intent) {
        List<ScanResult> list = scanner.getScanResults();

        for(ScanResult result : list){
            if(result.SSID.equals("Micro")){
                //Connect to THIS network
                connect(result.SSID);
                break;
            }
        }
    }

    public void connect(String name){
        String password = "logitech";
        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = "\"" + name + "\"";
        conf.preSharedKey = "\""+ password +"\"";

        scanner.addNetwork(conf);

        List<WifiConfiguration> list = scanner.getConfiguredNetworks();
        for( WifiConfiguration i : list ) {
            if(i.SSID != null && i.SSID.equals("\"" + name + "\"")) {

                int neiID = list.get(0).networkId;

                Log.d(TAG, "" + neiID);
                scanner.disconnect();
                scanner.enableNetwork(i.networkId, true);
                scanner.reconnect();
                break;
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

经过一些搜索,我发现这一行应该可以帮助你getprop net.dns1

它获取DNS服务器,如果您没有设置默认网关以外的它,它是默认网关,如果您没有设置路由器以外的默认网关,则默认网关是您的路由器,除非指定为ipv6,否则IP通常表示ipv4。

希望这有帮助

来源:Get gateway ip address in androidWhat is my DNS server