AdguardTeam / AdguardTeam/AdGuardHome
Local DNS Test page
- Lingua principale
- TypeScript
- Stelle
- 36.9k
- Fork
- 2.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
### 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()](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/dns/resolve)) to check if certain functionality is working (Similar to [ag dns overview test](https://adguard.com/en/adguard-dns/overview.html)).
**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
```batch
@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
```csharp
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;
}
}
}
```
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.