Skip to content

Commit

Permalink
Prevent IPv6 DNS servers from being used
Browse files Browse the repository at this point in the history
Also show the currently used DNS server in the runtime stats
  • Loading branch information
emanuele-f committed Feb 14, 2021
1 parent 49921a7 commit 3235c03
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ public static Prefs.DumpMode getDumpMode() {
return((INSTANCE != null) ? INSTANCE.dump_mode : Prefs.DumpMode.NONE);
}

public static String getDNSServer() {
return((INSTANCE != null) ? INSTANCE.getPublicDns() : "");
}

/* Stop a running VPN service */
public static void stopService() {
if (INSTANCE != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class StatsActivity extends AppCompatActivity {
TextView mTotConns;
TextView mMaxFd;
TextView mOpenSocks;
TextView mDnsServer;
TextView mDnsQueries;

@Override
Expand All @@ -42,6 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
mMaxFd = findViewById(R.id.max_fd);
mOpenSocks = findViewById(R.id.open_sockets);
mDnsQueries = findViewById(R.id.dns_queries);
mDnsServer = findViewById(R.id.dns_server);

LocalBroadcastManager bcast_man = LocalBroadcastManager.getInstance(this);

Expand Down Expand Up @@ -89,6 +91,7 @@ private void updateVPNStats(Intent intent) {
mMaxFd.setText(Utils.formatNumber(this, stats.max_fd));
mOpenSocks.setText(Utils.formatNumber(this, stats.num_open_sockets));
mDnsQueries.setText(Utils.formatNumber(this, stats.num_dns_queries));
mDnsServer.setText(CaptureService.getDNSServer());

if(stats.num_dropped_conns > 0)
mDroppedConns.setTextColor(Color.RED);
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/emanuelef/remote_capture/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import androidx.core.content.ContextCompat;

import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -147,8 +148,12 @@ static String getDnsServer(Context context) {
if(props != null) {
List<InetAddress> dns_servers = props.getDnsServers();

if (dns_servers.size() > 0)
return dns_servers.get(0).getHostAddress();
for(InetAddress addr : dns_servers) {
// Get the first IPv4 DNS server
if(addr instanceof Inet4Address) {
return addr.getHostAddress();
}
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/activity_stats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ android:layout_height="fill_parent">
android:textIsSelectable="true" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="4dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.60"
android:textStyle="bold"
android:text="@string/dns_server" />
<TextView
android:id="@+id/dns_server"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:textIsSelectable="true" />
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
<string name="packets_sent">Packets Sent</string>
<string name="packets_rcvd">Packets Received</string>
<string name="dns_queries">DNS Queries</string>
<string name="dns_server">DNS Server</string>
</resources>

0 comments on commit 3235c03

Please sign in to comment.