Dim strIPAddress
Dim strSubnetMask
Dim strGateway
Dim strDns1
Dim strDns2
Dim temp
'輸入IP
temp=InputBox("Please Enter IP : (or input DHCP)","GFI IP Setting")
'如果是DHCP就不做任何事
If temp <> "DHCP" Then
strIPAddress = temp
strSubnetMask = "255.255.255.0"
'計算 Gateway , 本例的Gateway 為 192.168.x.254 ,x為網段
intLastDecimal = 1
For intCounter = 1 to 3
intLastDecimal = InStr(intLastDecimal, strIPAddress , ".") + 1
Next
iNewLength = intLastDecimal-2
strNewIP = Left(strIPAddress , iNewLength )
strNewIP =strNewIP & ".254"
'end 計算Gateway
strGateway = strNewIP
'定義好DNS
strDns1 = "168.95.1.1"
strDns2 = "8.8.8.8"
'宣告使用shell
Set objShell = WScript.CreateObject("Wscript.Shell")
'透過netsh指令來修改IP
objShell.Run "netsh interface ip set address ""區域連線"" static " & strIPAddress & " " & strSubnetMask & " " & strGateway & " " , 0, True
'設定第一組DNS
objShell.Run "netsh interface ip set dns ""區域連線"" static "& strDns1, 0, True
'加入第2組DNS
objShell.Run "netsh interface ip add dns ""區域連線"" addr="& strDns2, 0, True
'Wscript.Echo "netsh interface ip set address ""區域連線"" static " & strIPAddress & " " & strSubnetMask & " " & strGateway & " "
Set objShell = Nothing
WScript.Quit
End If
沒有留言:
張貼留言