-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiHoleBackgroundDiag.ps1
More file actions
66 lines (60 loc) · 2.38 KB
/
PiHoleBackgroundDiag.ps1
File metadata and controls
66 lines (60 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#Getting Administrative Rights (DNS can't be changed without these rights)
param([switch]$Elevated)
function Check-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Check-Admin) -eq $false) {
if ($elevated)
{
# Couldn't set as Admin, quits the program
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
#Sets the system policy to run unsigned commands
Set-ExecutionPolicy RemoteSigned
Set-Variable -Name "Default_DNS_IP" -Value "192.168.0.1"
Set-Variable -Name "PiHole_DNS_IP" -Value "192.168.1.8"
Set-Variable -Name "current_DNS_IP" -Value (Get-DnsClientServerAddress -InterfaceAlias Wi-Fi -AddressFamily IPv4 | Select-Object –ExpandProperty ServerAddresses)
if ($current_DNS_IP -eq $PiHole_DNS_IP){
Write-Output "Currently set to PiHole"
Resolve-DnsName -Name www.apple.com -Server $PiHole_DNS_IP -Type A
if ($?){
Write-Output "PiHole Is Up, System Functioning Correctly"
}
else{
Write-Output "PiHole is Down"
Resolve-DnsName -Name www.apple.com -Server $Default_DNS_IP -Type A
if ($?){
Write-Output "Default DNS Is Up"
#SET TO DEFAULT DNS
Set-DnsClientServerAddress -InterfaceAlias Wi-Fi -ResetServerAddresses
Write-Output "Default DNS Restored (FAILSAFE MODE)"
}
else{
Write-Output "Default DNS is Down (PROBLEM IS NOT ON OUR END)"
}
}
}
else{
Write-Output "Not set to PiHole, Checking if PiHole is up."
Resolve-DnsName -Name www.apple.com -Server $PiHole_DNS_IP -Type A
if ($?){
Write-Output "PiHole Is Up"
#SET TO PIHOLE
Set-DnsClientServerAddress -InterfaceAlias Wi-Fi -ServerAddresses $PiHole_DNS_IP
Write-Output "DNS Set to PiHole"
}
else{
Resolve-DnsName -Name www.apple.com -Server $Default_DNS_IP -Type A
if ($?){
Write-Output "PiHole is Down. Default DNS is up. (FAILSAFE MODE)"
}
else{
Write-Output "PiHole and Failsafe are down. Internet is likely down. Exiting without making changes..."
}
}
}