|
/** |
|
* Windows DNS Switcher - Don't wear out your mouse trying to change your DNS server adresses. |
|
* @author Halil Ozgur |
|
* @license GPL Licence |
|
*/ |
|
|
|
var dnsler = [ |
|
["Empty (DHCP-Auto)", []], |
|
["OpenDNS", ["208.67.222.222", "208.67.220.220"]], |
|
["Google DNS", ["8.8.8.8", "8.8.4.4"]], |
|
["Comodo Secure DNS", ["156.154.70.22", "156.154.71.22"]] |
|
]; |
|
|
|
var Regkey = "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\"; |
|
var strComputer = "."; |
|
var objWMIService = GetObject("winmgmts:\\\\" + strComputer + "\\root\\cimv2"); |
|
var WshShell = WScript.CreateObject("WScript.Shell") |
|
var IPDevSet = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE"); |
|
|
|
function dnsLblAra(aDnsler) |
|
{ |
|
for (var i = 0; i < dnsler.length; i++) { |
|
if (aDnsler.join(', ') == dnsler[i][1].join(', ')) { |
|
return dnsler[i][0]; |
|
} |
|
} |
|
return ""; |
|
} |
|
|
|
function dnsFmt(aDnsler) |
|
{ |
|
var ret = aDnsler.join(', '); |
|
var dnsLbl = dnsLblAra(aDnsler); |
|
if (dnsLbl != "") { |
|
if (aDnsler.length == 0) { |
|
ret += dnsLbl; |
|
} else { |
|
ret += " (" + dnsLbl + ")"; |
|
} |
|
} else { |
|
ret += ""; |
|
} |
|
return ret; |
|
} |
|
|
|
function getItemDns(oItem) |
|
{ |
|
if (oItem.DNSServerSearchOrder != null) { |
|
return oItem.DNSServerSearchOrder.toArray(); |
|
} else { |
|
return []; |
|
} |
|
} |
|
|
|
WScript.Echo("Current DNS Servers :\n"); |
|
for (var enumerator = new Enumerator(IPDevSet); !enumerator.atEnd(); enumerator.moveNext()) { |
|
var item = enumerator.item(); |
|
WScript.Echo(item.Caption + " :\n" + dnsFmt(getItemDns(item)) + "\n"); |
|
} |
|
|
|
WScript.Echo("Please choose the new DNS server(s):"); |
|
|
|
var secim = null; |
|
while (secim == null) { |
|
for (var i = 0; i < dnsler.length; i++) { |
|
WScript.Echo(i + " : " + dnsler[i][0]); |
|
} |
|
WScript.StdOut.Write(" > "); |
|
secim = WScript.StdIn.ReadLine(); |
|
secim = parseInt(secim); |
|
if (!dnsler[secim]) { |
|
WScript.Echo("Invalid choice. Please try again.\n"); |
|
secim = null; |
|
} |
|
} |
|
|
|
var secilenDNSler = dnsler[secim][1]; |
|
|
|
for (var enumerator = new Enumerator(IPDevSet) ; !enumerator.atEnd(); enumerator.moveNext()) { |
|
var item = enumerator.item(); |
|
eskiDNSler = getItemDns(item); |
|
var kod = item.SetDNSServerSearchOrder(Array(secilenDNSler[0], secilenDNSler[1])); |
|
WScript.Echo(item.Caption + " :\n[" + kod + '] ' + dnsFmt(eskiDNSler) + " -> " + dnsFmt(secilenDNSler) + "\n"); |
|
} |
|
|
|
WshShell.Exec("ipconfig /flushdns"); |
|
WScript.Echo("\"ipconfig /flushdns\" executed."); |
|
WScript.Sleep(3750); |