简体   繁体   English

通过python在Windows中设置代理

[英]Proxy setting in windows via python

In Windows 7 for giving proxy, 在Windows 7中提供代理,

So, using the GUI, I would go: 因此,使用GUI,我会:

Start → Control Panel → Network and Internet → Internet Options → Connections → LAN Settings 开始→控制面板→网络和Internet→Internet选项→连接→LAN设置

and then 接着

1)use automatic configuration script 1)使用自动配置脚本

2)give an ip and port 2)给一个ip和端口

Is there a command to do these tasks via cmd line (so that i can use it through subprocess) Or is there module in python. 是否有命令通过cmd行执行这些任务(以便我可以通过子进程使用它)或python中是否存在模块。

There is one in python 2.7 called _winrgr but 2nd part of the question can be solved using that.What about the first one? 在python 2.7中有一个叫做_winrgr,但是问题的第二部分可以用那个解决。第一个呢?

Tried using netsh winhttp set proxy but there was no change in proxy setting thought command line said that proxy has been changed. 使用netsh winhttp设置代理进行了尝试,但是代理设置没有变化,但命令行认为代理已更改。

I solved the first part via _winreg. 我通过_winreg解决了第一部分。

key=registry.OpenKey(registry.HKEY_CURRENT_USER,"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections",0,registry.KEY_ALL_ACCESS)
(value, regtype) = registry.QueryValueEx(key, "DefaultConnectionSettings")
if regtype == registry.REG_BINARY:
     value = value[:8] + chr(0x03) + value[9:]
registry.SetValueEx(key, "DefaultConnectionSettings", None, regtype, value)

A value of 3 mean use manual settings. 值3表示使用手动设置。 A value of 9 mean use automatic settings. 值9表示使用自动设置。 A value of 1 means it is not enabled. 值为1表示未启用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM