[英]How can i get all the ip address of access points in the wifi ? Android
我无法获取IP地址...通过wifi扫描获取所有接入点的IP地址是否正确?
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 (!inetAddress.isLoopbackAddress()) {
Toast.makeText(wifiDemo, TAG + "IP " + inetAddress.getHostAddress().toString(), Toast.LENGTH_LONG).show();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
}
您是否尝试过NetworkInterface.getNetworkInterfaces()
方法来获取所有接口? 然后迭代从每个接口获取IP。
WiFi接入点没有IP地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.