Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change DNS Configuration

Status
Not open for further replies.

cdonkin

IS-IT--Management
May 22, 2009
6
US
Hello,

I need to change the DNS configuration of users machines based on their circumstances. If they are using a VPN to access a page it needs to be one thing, if they are connecting through the office it needs to be another. I have managed to successfully do this using netsh for example :

Set WshShell = WScript.CreateObject("Wscript.Shell")

WshShell.Run "cmd /c netsh interface ip set DNS ""Local Area Connection"" Static 123.242.121.23",0

However if the user is connecting using Local Area Connection 2 or Local Are connection 7 etc this script won't work and is causing problems.

Is there a way of detecting which Local Area Connections are being used by the machine, and then is there a way of running the script above but having ""Local Area Connetion"" being a variable, where the variable is assigned the value of the Local Area Connection on the Users PC. So if i was conencted using LAN 3 it would input ""Local Area Connection 3"" where ""Local Area Connection"" is.

Thanks in advance for any guidance, pointers, code snippets, advice anything thanks,
 
I had to tackle a similar situation recently. Assuming you can identify the VPN systems based on the IP range, you should be able easily modify my script.

Code:
'==========================================================================
'
' NAME: Set_DNS_WINS_Remotely.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL   : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]    
' COPYRIGHT (C) 2009 All rights reserved
' DATE  : 4/24/2009
'
' COMMENT: 
'
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'==========================================================================


strComputer = InputBox("Enter Computer Name","Enter Target")  

strWins1 = "192.168.20.150"
strWins2 = "192.168.20.41"
strDNS1 = "192.168.20.150"
strDNS2 = "192.168.20.41"
 
Set objWMIService = GetObject("winmgmts:" _  
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  
  
Set colNetCards = objWMIService.ExecQuery _  
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled =  True")  
  
For Each objNetCard in colNetCards  
  arrDNSServers = Array(strDNS1, strDNS2)  
  objNetCard.SetDNSServerSearchOrder(arrDNSServers)  
  intSetWINS = objNetCard.SetWINSServer(strWINS1, strWINS2)
  If intSetWINSServer = 0 Then
    WScript.Echo "Success! WINS & DNS servers configured."
  ElseIf intSetWINSServer = 1 Then
    WScript.Echo "WINS  & DNS servers configured, please reboot."
  Else
    WScript.Echo "Error!! Unable to configure WINS & DNS servers."
  End If
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top