Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local DNS Test page #1117

Open
2 tasks
Bluscream opened this issue Oct 24, 2019 · 1 comment
Open
2 tasks

Local DNS Test page #1117

Bluscream opened this issue Oct 24, 2019 · 1 comment

Comments

@Bluscream
Copy link

Bluscream commented Oct 24, 2019

Problem Description

Sometimes machines have set alternate DNS servers that resolve domains even when blocked by AGHome. In these and similar cases it can be tedious to check what's wrong.

Proposed Solution

A website within AGHome that has local javascript (eg: dns.resolve()) to check if certain functionality is working (Similar to ag dns overview test).

Checks:

  • Resolving of some commonly used domains working? (google,bing,etc...)
  • Blocked domain response working (random blocked domain provided by aghome on page load)

Alternatives Considered

Some kind of app/script for many operating systems that would do these checks.

Additional Information

Example Batch Script
@echo off
title %date% - %time%
@echo ### Testing google.com on Default ###
color a
nslookup google.com
echo.
@echo ### Testing google.com on AdguardHome DNS ###
nslookup google.com 192.168.2.43
nslookup google.com 192.168.2.47
PAUSE
echo.
@echo ### Testing myteamspeak.com on Default ###
nslookup myteamspeak.com
echo.
@echo ### Testing myteamspeak.com on AdguardHome DNS ###
nslookup myteamspeak.com 192.168.2.43
nslookup myteamspeak.com 192.168.2.47
echo.
PAUSE
Example C# Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;

namespace DNSTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            DisplayDnsAddresses();
            Console.ReadKey();
            Main(args);
        }

        public static void DisplayDnsAddresses()
        {
            Console.Write("Enter Domain: ");
            var domain = Console.ReadLine();
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
                IPAddressCollection dnsServers = adapterProperties.DnsAddresses;
                if (dnsServers.Count > 0)
                {
                    Console.WriteLine("{0} ({1})", adapter.Description, dnsServers.Count);
                    foreach (IPAddress dns in dnsServers)
                    {
                        var getHostByName = DoGetHostByName(domain) ? "Y" : "N"; // "✅" : "❌";
                        var resolved = DoResolve(domain) ? "Y" : "N";
                        var hostEntry = DoGetHostEntry(domain) ? "Y" : "N";
                        var isValid = CheckIPValid(dns.ToString()) ? "Valid" : "Invalid";
                        Console.WriteLine("\t{0}\t\t[{1} {5}] Dns.GetHostByName: {2} Dns.Resolve: {3} Dns.GetHostEntry: {4}", dns, isValid, getHostByName, resolved, hostEntry, dns.AddressFamily);
                    }
                    Console.WriteLine();
                }
            }
        }

        public static bool CheckIPValid(string strIP)
        {
            IPAddress result = null;
            return
                !String.IsNullOrEmpty(strIP) &&
                IPAddress.TryParse(strIP, out result);
        }

        private static bool DoGetHostByName(string hostName)
        {
            try
            {
                IPHostEntry hostInfo = Dns.GetHostByName(hostName);
                // Get the IP address list that resolves to the host names contained in the
                // Alias property.
                IPAddress[] address = hostInfo.AddressList;
                // Get the alias names of the addresses in the IP address list.
                String[] alias = hostInfo.Aliases;

                // Console.WriteLine("Host name : " + hostInfo.HostName);
                // Console.WriteLine("\nAliases : ");
                for (int index = 0; index < alias.Length; index++)
                {
                    // Console.WriteLine(alias[index]);
                }
                // Console.WriteLine("\nIP address list : ");
                for (int index = 0; index < address.Length; index++)
                {
                    // Console.WriteLine(address[index]);
                }

                return true;
            }
            catch (SocketException e)
            {
                // Console.WriteLine("SocketException caught!!!");
                // Console.WriteLine("Source : " + e.Source);
                // Console.WriteLine("Message : " + e.Message);
            }
            catch (ArgumentNullException e)
            {
                // Console.WriteLine("ArgumentNullException caught!!!");
                // Console.WriteLine("Source : " + e.Source);
                // Console.WriteLine("Message : " + e.Message);
            }
            catch (Exception e)
            {
                // Console.WriteLine("Exception caught!!!");
                // Console.WriteLine("Source : " + e.Source);
                // Console.WriteLine("Message : " + e.Message);
            }

            return false;
        }

        private static bool DoResolve(string hostString)
        {
            try
            {
                IPHostEntry hostInfo = Dns.Resolve(hostString);
                // Get the IP address list that resolves to the host names contained in the
                // Alias property.
                IPAddress[] address = hostInfo.AddressList;
                // Get the alias names of the addresses in the IP address list.
                String[] alias = hostInfo.Aliases;

                // Console.WriteLine("Host name : " + hostInfo.HostName);
                // Console.WriteLine("\nAliases : ");
                for (int index = 0; index < alias.Length; index++)
                {
                    // Console.WriteLine(alias[index]);
                }
                // Console.WriteLine("\nIP Address list :");
                for (int index = 0; index < address.Length; index++)
                {
                    // Console.WriteLine(address[index]);
                }

                return true;
            }
            catch (SocketException e)
            {
                // Console.WriteLine("SocketException caught!!!");
                // Console.WriteLine("Source : " + e.Source);
                // Console.WriteLine("Message : " + e.Message);
            }
            catch (ArgumentNullException e)
            {
                // Console.WriteLine("ArgumentNullException caught!!!");
                // Console.WriteLine("Source : " + e.Source);
                // Console.WriteLine("Message : " + e.Message);
            }
            catch (NullReferenceException e)
            {
                // Console.WriteLine("NullReferenceException caught!!!");
                // Console.WriteLine("Source : " + e.Source);
                // Console.WriteLine("Message : " + e.Message);
            }
            catch (Exception e)
            {
                // Console.WriteLine("Exception caught!!!");
                // Console.WriteLine("Source : " + e.Source);
                // Console.WriteLine("Message : " + e.Message);
            }

            return false;
        }

        public static bool DoGetHostEntry(string hostname)
        {
            try
            {
                IPHostEntry host = Dns.GetHostEntry(hostname);

                // Console.WriteLine($"GetHostEntry({hostname}) returns:");

                foreach (IPAddress address in host.AddressList)
                {
                    // Console.WriteLine($"    {address}");
                }

                return true;
            }
            catch (Exception e)
            {
                // Console.WriteLine("Exception caught!!!");
                // Console.WriteLine("Source : " + e.Source);
                // Console.WriteLine("Message : " + e.Message);
            }

            return false;
        }
    }
}
@Bluscream
Copy link
Author

For extra points the test at https://adguard.com/en/adguard-dns/overview.html could return different strings for aghome and adguardforandroid DNS blockers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants