3

I am new to Python and would like to write a script to change Windows proxy settings based on the network I am connected to. Is there any existing python module I can use? Appreciate your help.

Thanks, Sethu

2 Answers 2

3

I would use winreg and query the settings directly from the registry.

 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet
 Settings] "MigrateProxy"=dword:00000001 
 "ProxyEnable"=dword:00000001
 "ProxyHttp1.1"=dword:00000000
 "ProxyServer"="http://ProxyServername:80" 
 "ProxyOverride"="<local>"

For example, something like:

import _winreg

def getProxy():
    proxy = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")
    server, type = _winreg.QueryValueEx(proxy, "ProxyServer")
    enabled, type = _winreg.QueryValueEx(proxy, "ProxyEnable")
    if enabled:
        return server
    return None
Sign up to request clarification or add additional context in comments.

Comments

0

Cannot you set the HTTP_PROXY environment variable in Windows (either manually or within your program) for your application before sending the request? That should take care that any request you send it via urllib2 goes via Proxy.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.