- notageek.it di Mirko Iodice - http://www.notageek.it -

Remotely Change IP Gateway DNS and WINS

Posted By Mirko On 13 giugno 2007 @ 12:12 In Scripts | No Comments

Questo script permette di modificare da remoto tutti i principali parametri di configurazione assegnati ad una scheda di rete: Indirizzo IP, Subnet Mask, Default Gateway, suffisso DNS specifico per la connessione, server DNS Primario e secondario, server WINS primario e secondario.

E' necessario impostare tutte le variabili contenute nella sezione ' -------- Set variables here -------- del codice sorgente.

Potete eseguirlo indifferentemente con entrambi i motori WSH ("wscript.exe" oppure "cscript.exe").

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
48
49
50
51
52
53
54
55
'------------------- Declarations
dim aDNS(1)
Dim strWINS1
Dim strWINS2
dim strComputer
dim objWMIService
dim errDNS
dim errWINS
dim errEnable
dim errGateways
dim errDNSDomain
dim objItem 
dim colItems
'---------------------------------
 
' -------- Set variables here --------
 
' Set Computer Name or IP Address to run against
strComputer = "PC1"
 
' Set IP - Subnet - Gateway to assign
strIPAddress = Array("192.168.0.1")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.0.254")
strGatewaymetric = Array("1")
 
' Set DNS servers in search order to assign - or leave them blank
aDNS(0) = "208.67.222.222"
aDNS(1) = "208.67.220.220"
 
' Set connection-specific DNS suffix to assign - or leave it blank
dnsdomain = "domain.lan"
 
' Set WINS servers in search order to assign - or leave them blank
strWINS1 = ""
strWINS2 = ""
 
' -------- Variables End --------
 
On error resume next
set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = 1")
For Each objItem in colItems
	errDNS = objItem.SetDNSServerSearchOrder()
	errDNS = objItem.SetDNSServerSearchOrder(aDNS)
	errWINS = objItem.SetWINSServer (strWINS1,strWINS2)
	errDNSDomain = objItem.SetDNSDomain (dnsdomain)
	errGateways = objItem.SetGateways(strGateway, strGatewaymetric)
	errEnable = objItem.EnableStatic(strIPAddress, strSubnetMask)
Next
 
set objWMIService = Nothing
set colItems = Nothing
 
msgbox("Done")

Article printed from notageek.it di Mirko Iodice: http://www.notageek.it

URL to article: http://www.notageek.it/remotely-change-ip-gateway-dns-and-wins.html

URLs in this post:

[1] remote_change_ip_gateway_dns_wins.zip: http://www.notageek.it/wp-includes/files/remote_change_ip_gateway_dns_wins.zip

Copyright © 2009 notageek.it. All rights reserved.