-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshecan-dns.ps1
More file actions
44 lines (37 loc) · 1.32 KB
/
shecan-dns.ps1
File metadata and controls
44 lines (37 loc) · 1.32 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
#Requires -RunAsAdministrator
if ($args.count -ne 1 -or (($args[0] -ne "set") -and ($args[0] -ne "clear")))
{
$args.count
Write-Host "Error: Incorrect input arguments." -ForegroundColor red
$scriptName = Split-Path -Path $PSCommandPath -Leaf
Write-Host "Usage:" -ForegroundColor green
Write-Host $scriptName, "set # Sets Shekan DNS"
Write-Host $scriptName, "clear # Clears DNS"
exit 1
}
# Get primary interface index, source: "https://superuser.com/a/1626051/1797013"
$desiredInterfaceIndex = Get-NetRoute | % { Process { If (!$_.RouteMetric) { $_.ifIndex } } };
Write-Host "Selected Interface: " -ForegroundColor green
Get-NetAdapter -InterfaceIndex $desiredInterfaceIndex | Format-List -Property "Name", "InterfaceDescription", "InterfaceName"
# Shekan DNS, "https://shecan.ir/"
$shekanPrimaryDNS = "178.22.122.100"
$shekanSecondaryDNS = "185.51.200.2"
# Change DNS, source: "https://superuser.com/a/1625641/1797013"
if ($args[0] -eq "set")
{
Set-DNSClientServerAddress -interfaceIndex $desiredInterfaceIndex -ServerAddresses ("$shekanPrimaryDNS", "$shekanSecondaryDNS");
}
else
{
Set-DnsClientServerAddress -interfaceIndex $desiredInterfaceIndex -ResetServerAddresses
}
if ($?)
{
Write-Host "DNS changed successfully." -ForegroundColor green
exit 0
}
else
{
Write-Host "DNS failed to change." -ForegroundColor red
exit 2
}