0

I need to get router ipv4 address to my android phone. Is it possible to do that? It's easy to get ipv4 from computer I jus need to type ipconfig to cmdenter image description here

But how to get already connected router ipv4 from android device? Here's my android code where I connect to router

 @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;
            }
        }
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
David
  • 3,055
  • 4
  • 30
  • 73
  • You'll find answers here : http://stackoverflow.com/questions/11015912/how-do-i-get-ip-address-in-ipv4-format and here :http://stackoverflow.com/questions/6064510/how-to-get-ip-address-of-the-device – Tolga Varol Aug 19 '15 at 16:53
  • Thanks, But all these answers get IP adress of android device! I need to get router ipv4 adress! – David Aug 21 '15 at 13:18

1 Answers1

0

After some search I've found that this line should help you getprop net.dns1

It gets the DNS server and if you haven't set it other than your default gateway, it is the default gateway, and if you haven't set your default gateway other than your router, your default gateway is your router, and unless specified as ipv6, IP usually denotes ipv4.

Hope this helps

Sources :Get gateway ip address in android, What is my DNS server

Community
  • 1
  • 1
Tolga Varol
  • 1,036
  • 1
  • 16
  • 21