Reputation: 1088
Able to get the WI-FI IP address using the below code.
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE); String ipAddress = Formatter.formatIpAddress(wifiManager.getConnectionInfo().getIpAddress());
"EthernetManager" is not acceptable in the code, May I know how to get the IP address of the ethernet?
Upvotes: 1
Views: 2330
Reputation: 110
You can get LAN IP the following way:
ConnectivityManager manager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
LinkProperties props = manager.getLinkProperties(manager.getActiveNetwork());
props.getLinkAddresses() ; //May be array. Contains lan ips
This will give you an array of local IP addresses including IPv6.So depending on what you require you need to manually get the desired IP inside the array. Also, make sure you have added android.permission.ACCESS_NETWORK_STATE in Android Manifest.
Upvotes: 2