| Author |
Topic  |
|
|
Edwardthe1st
Old Timer
  
USA
458 Posts
Status: offline |
Posted - 03/26/2010 : 1:13:03 PM
|
Hello, I'm using the following script to try and set the default (unconditional) forwarders for our DNS servers (domain controllers): ============================================= ' Sets the default forwarders on DNS servers listed in a text file.
On Error Resume Next
'Text file to read from with each server name to a line Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ ("c:\Test\Servers.txt", ForReading)
'Text file to write results to. Set objTextFile1 = objFSO.OpenTextFile _ ("c:\Test\DNS Forwarder Results.txt", ForWriting, True) objTextFile1.WriteLine("Script began execution at " & Now() & "!" & VBCRLF)
'Start of the work section loop Do Until objTextFile.AtEndOfStream strComputer = objTextFile.Readline
'Connect to the DNS service on the server. If the server is inaccessible for some reason, log an error. set objDNS = GetObject("winMgmts:\\" & strComputer & "\root\MicrosoftDNS")
if err.number <> 0 then objtextFile1.WriteLine(strComputer & vbTab & "is inaccessible - setting default forwarders failed!" & VBCRLF) else
arrForwarders = Array("1.1.1.1","2.2.2.2","3.3.3.3")
'Change the default forwarders set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name=""strComputer""") objDNSServer.Forwarders = arrForwarders objDNSServer.Put_
objtextFile1.WriteLine(strComputer & vbTab & "- "Successfully set default forwarders"!" & VBCRLF)
End if
Loop
objTextFile1.WriteLine("Script completed execution at " & Now() & "!") objTextFile.Close objTextFile1.Close
Wscript.echo "Default forwarders update has finished - review the log for results." ====================================== Unfortunately the script errors out with the following: Line 34 Character 50 Expected ")" Error 800A03EE ====================================== Line 34 is "objtextFile1.WriteLine(strComputer & vbTab & "- "Successfully set default forwarders"!" & VBCRLF)
The script "looks" okay to me, so what am I missing here? Thanks in advance
|
I <3 AD. |
|
|
Edwardthe1st
Old Timer
  
USA
458 Posts
Status: offline |
Posted - 03/26/2010 : 1:38:27 PM
|
Never mind, I got it working. Here is the corrected code in case anyone else would like to use it. =============================================================== ' Sets the default forwarders on DNS servers listed in a text file.
On Error Resume Next
Const ForReading = 1 Const ForWriting = 2
'Text file to read from with each server name to a line Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ ("c:\Test\Servers.txt", ForReading)
'Text file to write results to. Set objTextFile1 = objFSO.OpenTextFile _ ("c:\Test\DNS Forwarder Results.txt", ForWriting, True) objTextFile1.WriteLine("Script began execution at " & Now() & "!" & VBCRLF)
'Start of the work section loop Do Until objTextFile.AtEndOfStream strComputer = objTextFile.Readline
'Connect to the DNS service on the server. If the server is inaccessible for some reason, log an error. set objDNS = GetObject("winMgmts:\\" & strComputer & "\root\MicrosoftDNS")
if err.number <> 0 then objtextFile1.WriteLine(strComputer & vbTab & "is inaccessible - setting default forwarders failed!" & VBCRLF) else
arrForwarders = Array("1.1.1.1","2.2.2.2","3.3.3.3")
'Change the default forwarders set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name=""strComputer""") objDNSServer.Forwarders = arrForwarders objDNSServer.Put_
objtextFile1.WriteLine(strComputer & vbTab & "- Successfully set default forwarders!" & VBCRLF)
End if
Loop
objTextFile1.WriteLine("Script completed execution at " & Now() & "!") objTextFile.Close objTextFile1.Close
Wscript.echo "Default forwarders update has finished - review the log for results."
|
I <3 AD. |
 |
|
|
sheepmaster
Welcome Newcomer
Italy
4 Posts
Status: offline |
Posted - 03/16/2011 : 09:52:21 AM
|
I'm trying to use your script with my windows 2008 DNS server to open the restrictions to my users at lunch-time because I use opendns Web Content Filtering [09-13 and 14-18 with opendns, 18-09 and 13-14 with googledns] but this is my error Script began execution at 16/03/2011 14.47.36! resolver1.opendns.com is inaccessible - setting default forwarders failed! Script completed execution at 16/03/2011 14.47.57!
can I skip the connection to the DNS service on the server? I've put the resolver1.opendns.com in the txt file c:\Test\Servers.txt is this correct? thank you r. |
renato:rossetti IT consultant:consulente informatico via donatello 13 - 20014 nerviano (mi) mobile +39.3472547547 fax +39.02.700538071 skype:progetto_mayhem http://www.progettomayhem.com before printing this message, make sure it's necessary...environment is in our hand |
 |
|
|
Edwardthe1st
Old Timer
  
USA
458 Posts
Status: offline |
Posted - 03/21/2011 : 10:37:54 AM
|
Hello, sorry for the late reply. The text file, Servers.txt, contains the names of your internal DNS servers that you want to set (unconditional) forwarders against using the script above. Is resolver1.opendns.com an internal Windows box on your network, or is it the system your internal DNS servers need to forward to? The variable "arrForwarders" contains the IP addresses of systems (normally ISP DNS, DNS caching server.etc) to send queries to.
> can I skip the connection to the DNS service on the server? I'm not sure I follow you here.
> I've put the resolver1.opendns.com in the txt file c:\Test\Servers.txt is this correct? It is if resolver1.opendns.com is an internal box that needs to be pointed to someone else for external DNS queries. If that is the case, you need to provide ip addresses in the arrForwarders variable that resolver1.opendns.com will forward to when it can't answer a query from clients.
Let me know if there are any questions. |
I <3 AD. |
 |
|
|
sheepmaster
Welcome Newcomer
Italy
4 Posts
Status: offline |
Posted - 03/22/2011 : 07:03:21 AM
|
resolver1.opendns.com is the external DNS server my internal DNS servers need to forward to I want to forward, working time to opendns and off-working time to google [without Web Content Filtering] can I use your script? It's possible to schedule to change the DNS forwarders? thank you |
renato:rossetti IT consultant:consulente informatico via donatello 13 - 20014 nerviano (mi) mobile +39.3472547547 fax +39.02.700538071 skype:progetto_mayhem http://www.progettomayhem.com before printing this message, make sure it's necessary...environment is in our hand |
 |
|
|
Edwardthe1st
Old Timer
  
USA
458 Posts
Status: offline |
Posted - 03/22/2011 : 10:35:35 AM
|
Hi, You should be able to utilize the script for this. Create two copies and modify the arrForwarders line like so: 1. For the business hours script, arrForwarders = Array("<IP address of resolver1-opendns.com>") 2. For the after hours script, arrForwarders = Array("<IP address of google DNS>")
> It's possible to schedule to change the DNS forwarders? Yes, you could set a scheduled task using triggers (i.e. 9 am and 5 pm) to run the scripts at the appropriate times on the DNS servers that need to be changed.
I hope this helps. |
I <3 AD. |
 |
|
|
sheepmaster
Welcome Newcomer
Italy
4 Posts
Status: offline |
Posted - 03/22/2011 : 11:40:21 AM
|
I'm so sorry but maybe I'm such a newbie in scripting... It's better cut&paste the scripts they doesn't work :-(
thanks in advance
--------------------------------------------------------
' Sets the default forwarders on DNS servers listed in a text file.
On Error Resume Next
Const ForReading = 1 Const ForWriting = 2
'Text file to read from with each server name to a line Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ ("C:\Scripts\GoogleDNSforwarders.txt", ForReading)
'Text file to write results to. Set objTextFile1 = objFSO.OpenTextFile _ ("C:\Scripts\GoogleDNSforwarderResults.txt", ForWriting, True) objTextFile1.WriteLine("Script began execution at " & Now() & "!" & VBCRLF)
'Start of the work section loop Do Until objTextFile.AtEndOfStream strComputer = objTextFile.Readline
'Connect to the DNS service on the server. If the server is inaccessible for some reason, log an error. set objDNS = GetObject("winMgmts:\\" & strComputer & "\root\MicrosoftDNS")
if err.number <> 0 then objtextFile1.WriteLine(strComputer & vbTab & "is inaccessible - setting default forwarders failed!" & VBCRLF) else
arrForwarders = Array("8.8.8.8")
'Change the default forwarders set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name=""strComputer""") objDNSServer.Forwarders = arrForwarders objDNSServer.Put_
objtextFile1.WriteLine(strComputer & vbTab & "- Successfully set default forwarders!" & VBCRLF)
End if
Loop
objTextFile1.WriteLine("Script completed execution at " & Now() & "!") objTextFile.Close objTextFile1.Close
Wscript.echo "Default forwarders update has finished - review the log for results."
----------------------------------------------------------------------------------- ' Sets the default forwarders on DNS servers listed in a text file.
On Error Resume Next
Const ForReading = 1 Const ForWriting = 2
'Text file to read from with each server name to a line Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ ("C:\Scripts\OpenDNSforwarders.txt", ForReading)
'Text file to write results to. Set objTextFile1 = objFSO.OpenTextFile _ ("C:\Scripts\OpenDNSforwarderResults.txt", ForWriting, True) objTextFile1.WriteLine("Script began execution at " & Now() & "!" & VBCRLF)
'Start of the work section loop Do Until objTextFile.AtEndOfStream strComputer = objTextFile.Readline
'Connect to the DNS service on the server. If the server is inaccessible for some reason, log an error. set objDNS = GetObject("winMgmts:\\" & strComputer & "\root\MicrosoftDNS")
if err.number <> 0 then objtextFile1.WriteLine(strComputer & vbTab & "is inaccessible - setting default forwarders failed!" & VBCRLF) else
arrForwarders = Array("208.67.220.220")
'Change the default forwarders set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name=""strComputer""") objDNSServer.Forwarders = arrForwarders objDNSServer.Put_
objtextFile1.WriteLine(strComputer & vbTab & "- Successfully set default forwarders!" & VBCRLF)
End if
Loop
objTextFile1.WriteLine("Script completed execution at " & Now() & "!") objTextFile.Close objTextFile1.Close
Wscript.echo "Default forwarders update has finished - review the log for results."
|
renato:rossetti IT consultant:consulente informatico via donatello 13 - 20014 nerviano (mi) mobile +39.3472547547 fax +39.02.700538071 skype:progetto_mayhem http://www.progettomayhem.com before printing this message, make sure it's necessary...environment is in our hand |
 |
|
|
Edwardthe1st
Old Timer
  
USA
458 Posts
Status: offline |
Posted - 03/22/2011 : 2:28:39 PM
|
| Don't worry, I was a newbie once as well. But to be honest it's definitely beneficial to learn some form of scripting so that you can automate things in general (this is a prime example!). Everything looks good, just be sure to include the names of your internal DNS servers (one per line) that need to be modified in the GoogleDNSforwarders.txt and OpenDNSforwarders.txt files and you should be good to go. Let me know how it goes. |
I <3 AD. |
 |
|
|
master811
Welcome Newcomer
2 Posts
Status: offline |
Posted - 03/24/2011 : 04:58:54 AM
|
Been looking for something exactly like this to do the same thing as sheepmaster. The only difference is running on SBS 2003. I've tried running the script, but am simply getting:
"8.8.8.8 is inaccessible - setting default forwarders failed!" in the resulting text file. I assume this is a vbs script correct? as I'm also completely new to scripting. |
Edited by - master811 on 03/24/2011 05:18:25 AM |
 |
|
|
Edwardthe1st
Old Timer
  
USA
458 Posts
Status: offline |
Posted - 03/24/2011 : 09:52:17 AM
|
yes this is a vbscript, and no worries. what is 8.8.8.8, the address of the external DNS server you're wanting to forward to, or is this the internal SBS system? the server text file the script uses for input contains the names (one to a line) of your internal DNS servers you want to set the forwarders on, and the script uses the ip address/adresses (of the external systems) specified in the variable "arrForwarders" to apply to your internal boxes.
hope this helps. |
I <3 AD. |
 |
|
|
sheepmaster
Welcome Newcomer
Italy
4 Posts
Status: offline |
Posted - 03/24/2011 : 1:06:35 PM
|
IT WORKS PERFECTLY!!! thank you sooo much ^_^ |
renato:rossetti IT consultant:consulente informatico via donatello 13 - 20014 nerviano (mi) mobile +39.3472547547 fax +39.02.700538071 skype:progetto_mayhem http://www.progettomayhem.com before printing this message, make sure it's necessary...environment is in our hand |
 |
|
|
Edwardthe1st
Old Timer
  
USA
458 Posts
Status: offline |
Posted - 03/24/2011 : 2:00:01 PM
|
| i'm very glad to hear that, and thanks for letting me know! |
I <3 AD. |
 |
|
|
master811
Welcome Newcomer
2 Posts
Status: offline |
Posted - 03/24/2011 : 2:36:02 PM
|
| Got this working as well thanks. Very useful! |
 |
|
| |
Topic  |
|