-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiHoleBackground.ps1
47 lines (43 loc) · 1.78 KB
/
PiHoleBackground.ps1
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
#THIS VERSION OF THE PROGRAM ASSUMES YOU ALREADY HAVE ADMIN RIGHTS.
Set-Variable -Name "Default_DNS_IP" -Value "10.128.128.128"
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..."
}
}
}