mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-06-19 21:05:25 +08:00
parent
4676e6f778
commit
44a9f1fb67
@ -31,5 +31,6 @@
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
</manifest>
|
||||
@ -237,9 +237,12 @@ public class MainActivity extends AppCompatActivity implements LoaderManager.Loa
|
||||
if (requestCode == REQUEST_CODE_VPN && resultCode == RESULT_OK) {
|
||||
Intent intent = new Intent(MainActivity.this, CaptureService.class);
|
||||
Bundle bundle = new Bundle();
|
||||
String dns_server = Utils.getDnsServer(getApplicationContext());
|
||||
|
||||
Log.i("Main", "Using DNS server " + dns_server);
|
||||
|
||||
// the configuration for the VPN
|
||||
bundle.putString("dns_server", "8.8.8.8"); // TODO: read system DNS
|
||||
bundle.putString("dns_server", dns_server);
|
||||
bundle.putString(Prefs.PREF_COLLECTOR_IP_KEY, getCollectorIPPref());
|
||||
bundle.putInt(Prefs.PREF_COLLECTOR_PORT_KEY, Integer.parseInt(getCollectorPortPref()));
|
||||
bundle.putInt(Prefs.PREF_UID_FILTER, mFilterUid);
|
||||
|
||||
@ -1,12 +1,17 @@
|
||||
package com.emanuelef.remote_capture;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
@ -51,6 +56,25 @@ public class Utils {
|
||||
return apps;
|
||||
}
|
||||
|
||||
public static String getDnsServer(Context context) {
|
||||
ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Service.CONNECTIVITY_SERVICE);
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Network net = conn.getActiveNetwork();
|
||||
|
||||
if(net != null) {
|
||||
List<InetAddress> dns_server = conn.getLinkProperties(net).getDnsServers();
|
||||
|
||||
for(InetAddress server : dns_server) {
|
||||
return server.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
return "8.8.8.8";
|
||||
}
|
||||
|
||||
public static long now() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
return(calendar.getTimeInMillis() / 1000);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user