如何在Android上找到非WiFi连接的DHCP信息?

时间:2015-10-13 18:31:37

标签: android dhcp

我有Android设备,它通过以太网连接到网络。如何获取此连接的DHCP信息?

2 个答案:

答案 0 :(得分:0)

您应该可以使用ConnectivityManager.getAllNetworks()来获取连接的网络阵列: http://developer.android.com/reference/android/net/ConnectivityManager.html#getAllNetworks()

然后Network.getSocketFactory()用于您的已连接网络。 SocketFactory将允许您检查可以在连接上创建的Socket

http://developer.android.com/reference/android/net/Network.html#getSocketFactory()

由此,只需从Socket创建一个SocketFactory.createSocket()即可获得您想要的信息,例如Socket.getLocalSocketAddress()等。

http://developer.android.com/reference/javax/net/SocketFactory.html#createSocket()

http://developer.android.com/reference/java/net/Socket.html

答案 1 :(得分:0)

对于非Wifi,没有WifiManager类。

ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Service.CONNECTIVITY_SERVICE);


                        Log.i("routes ", connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getRoutes().toString());
                        Log.i("domains ", connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getDomains().toString());
                        Log.i("ip address ", connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getLinkAddresses().toString());
                        Log.i("dns address ", connectivityManager.getLinkProperties(connectivityManager.getActiveNetwork()).getDnsServers().toString());