versuchen Sie dies:
private static class NetworkSniffTask extends AsyncTask<Void, Void, Void> {
private static final String TAG = "NetworkSniffTask";
private WeakReference<Context> mContextRef;
private NetworkSniffTask(Context context) {
mContextRef = new WeakReference<>(context);
}
@Override
protected Void doInBackground(Void... voids) {
Log.e(TAG, "Let's sniff the network");
try {
Context context = mContextRef.get();
if (context != null) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo connectionInfo = wm.getConnectionInfo();
int ipAddress = connectionInfo.getIpAddress();
String ipString = Formatter.formatIpAddress(ipAddress);
Log.e(TAG, "activeNetwork: " + String.valueOf(activeNetwork));
Log.e(TAG, "ipString: " + String.valueOf(ipString));
String prefix = ipString.substring(0, ipString.lastIndexOf(".") + 1);
Log.e(TAG, "prefix: " + prefix);
for (int i = 0; i < 255; i++) {
String testIp = prefix + String.valueOf(i);
InetAddress name = InetAddress.getByName(testIp);
String hostName = name.getCanonicalHostName();
if (name.isReachable(1000))
Log.e(TAG, "Host:" + hostName);
}
}
} catch (Throwable t) {
Log.e(TAG, "Well that's not good.", t);
}
return null;
}
}
Sie Ihre Subnetz-Maske von Wi-Fi bekommen können, und ping alle möglichen IP-Adressen in Ihrem Subnetz. –
con Sie zeigen mir bitte ein Beispiel? –
Nein, tut mir leid, ich werde dich nicht an deiner Stelle arbeiten lassen. Wenn Sie nicht wissen, wie Sie etwas Bestimmtes tun, wie Sie eine Subnetzmaske wfom wifi bekommen, sollten Sie zuerst googeln, und dann - stellen Sie eine Frage, wenn Sie kein Ergebnis finden –