Hello All,
As you may or may not be aware, you must configure the proxy settings for each user on a windows domain. The following script will configure the gateway as the proxy for each user that runs it. Since our organization uses linux based VPN routers with Squid web proxy to do content filtering, and access control, the gateway is always the proxy. We use the 172.x.x.x private range, so Im not 100% certain of the performance of this under other private net ranges.
On a side note, someone will probably mention that there's a way to retrieve the gateway with WMI, and they would be correct. The problem I've encountered with using WMI is that, sometimes, I get back information about the wrong network card on computers with more than one network card (especially our wireless tablets running windows XP tablet edition). The scripts that I have which use WMI, I still use a function similar to GrabGateway [GrabIP in my other scripts] as a fall-back if I get a 169.x.x.x IP.
If you are confused about what this script is doing, simply set DebugMode = true at the top of the script, and you'll get plenty of information out of it.
'######################################################################
'# proxy_config.vbs modified 2006.06.29 #
'# by big will #
'# #
'# purpose - determine local gateway IP, and set Internet Explorer #
'# to use that IP as it's proxy, thereby enabling Squid as the proxy. #
'######################################################################
Option Explicit
const DebugMode = false
function RegKeyExists(sKey)
'This function based on Günter Born's example code at
'http://ourworld.compuserve.com/homepages/Guenter_Born/WSHBazaar/WSH2.htm
'this is much simpler than the mostrosity that I wrote.
dim temp
dim oShell
set oShell = CreateObject("Wscript.Shell")
on error resume next
temp = oShell.RegRead(sKey)
if Err.Number <> 0 then
if DebugMode then
wscript.echo "Registry Key : " & sKey & " - did NOT exist."
end if
RegKeyExists = false
else
if DebugMode then
wscript.echo "Registry Key : " & sKey & " - FOUND!"
end if
RegKeyExists = true
end if
Err.Clear
end function
function GrabGateway()
dim objShell
dim objExec
dim strConsoleResults
dim strArr, ipArr
dim i
dim sTemp
'Shell out to run "route print", capture the output, and look
'for the default gateway. This is a dirty use of Split to do
'some work for us.
on error resume next
set objShell = CreateObject("WScript.Shell")
set objExec = objShell.Exec("route print")
GrabGateway = ""
strConsoleResults = lcase(objExec.StdOut.ReadAll)
strArr = split(strConsoleResults, chr(13))
for i = 0 to Ubound(strArr)
if inStr(strArr(i), "default gateway:") then
ipArr = split(strArr(i), " ")
sTemp = ipArr(ubound(ipArr))
GrabGateway = sTemp
if DebugMode then
wscript.echo sTemp
end if
end if
next
end function
function setProxy(strIP)
' Proxy Registry Keys
' [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Internet settings]
' "ProxyServer"="172.x.x.x:80"
' "ProxyEnable"=dword:00000001
' "ProxyOverride"="127.0.0.1"
const regKeyProxyServer = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet settings\ProxyServer"
const regKeyProxyEnable = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet settings\ProxyEnable"
const regKeyProxyOverride = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet settings\ProxyOverride"
dim oShell
dim regValueProxyServer
dim regValueProxyEnable
set oShell = CreateObject("WScript.Shell")
if RegKeyExists(regKeyProxyServer) then
regValueProxyServer = oShell.RegRead(regKeyProxyServer)
end if
if RegKeyExists(regKeyProxyEnable) then
regValueProxyEnable = oShell.RegRead(regKeyProxyEnable)
end if
if DebugMode then
wscript.echo "Current regValueProxyServer : " & regValueProxyServer
wscript.echo "strIP : " & strIP
end if
'change the following line to your class A range to enable for a different
'private net. ie: "192." or "10."
if (instr(strIP, "172.")) and (regValueProxyServer <> strIP & ":80") or (regValueProxyEnable <> 1) then
oShell.RegWrite regKeyProxyServer, strIP & ":80", "REG_SZ"
oShell.RegWrite regKeyProxyEnable, 1, "REG_DWORD"
oShell.RegWrite regKeyProxyOverride, "127.0.0.1;<local>", "REG_SZ"
if DebugMode then
wscript.echo "ran registry update"
end if
else
if DebugMode then
wscript.echo "Logic determined that current settings = derived settings."
end if
end if
end function
if DebugMode then
wscript.echo "Debug Mode ON!"
end if
setProxy GrabGateway
This script was written entirely in Notepad++, with tabstops set to 2.