我无法获取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();
}
}
答案 0 :(得分:0)
您是否尝试NetworkInterface.getNetworkInterfaces()
方法来获取所有接口?然后迭代以从每个接口获取IP。
答案 1 :(得分:0)
WiFi接入点没有IP地址。