windows 通过windows命令行设置代理,包括登录参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26992886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set proxy through windows command line including login parameters
提问by jave.web
I want to set a proxy throught the command line, first thing I found out is that you have to run command line with administrator rights- then the basic proxy set would be:
我想通过命令行设置代理,我发现的第一件事是您必须以管理员权限运行命令行- 那么基本代理集将是:
netsh winhttp set proxy SERVER:PORT
This works nice, but I also want to add a login. As you can see I've tried using netsh->winhttp, however manualdoes not say anything about the login part so I just tried:
这很好用,但我也想添加一个登录名。正如你所看到的,我已经尝试过使用 netsh->winhttp,但是手册没有说明登录部分,所以我只是尝试过:
netsh winhttp set proxy user:password@SERVER:PORT
This unfortunately does not work. Is it even possible to achieve something like this in netsh->winhttp?
不幸的是,这不起作用。甚至可以在 netsh->winhttp 中实现这样的功能吗?
If so, how? If not => what windows commands should I follow?
?O?r? ?i?s? ?t?h?i?s? ?m?o?r?e? ?e?a?s?i?l?y? ?a?c?h?i?e?v?e?a?b?l?e? ?t?h?r?o?u?g?h? ?s?o?m?e? ?W?i?n?d?o?w?s?A?P?I? ?(?e?.?g?.? ?u?s?i?n?g? ?C?/?C?+?+?)???
如果是这样,如何?如果不是 => 我应该遵循哪些 Windows 命令?
?或者??是??这个??更多的??容易地??a?c?h?i?e?v?e?a?b?l?e? ?通过??一些??W?i?n?d?o?w?s?A?P?I? ?(?e?.?g?.??u?s?i?n?g??C?/?C?+?+?)???
Thanks for help, please feel free to ask any questions if something is unclear.
感谢您的帮助,如果有不清楚的地方,请随时提出任何问题。
USING: Windows 7, cmd.exe, netsh->winhttp
使用:Windows 7、cmd.exe、netsh->winhttp
EDIT:This looks like the C++ way: http://msdn.microsoft.com/en-us/library/windows/desktop/aa383144(v=vs.85).aspx, but a better way for C++ might be to go this way: http://msdn.microsoft.com/en-us/library/windows/desktop/aa385384(v=vs.85).aspx#general_option, - so the remaining question is how to achieve this in command line generally (or even better command-line->netsh->winhttp)?
编辑:这看起来像 C++ 方式:http://msdn.microsoft.com/en-us/library/windows/desktop/aa383144(v=vs.85).aspx,但 C++ 的更好方法可能是去这样:http://msdn.microsoft.com/en-us/library/windows/desktop/aa385384(v=vs.85).aspx#general_option, - 所以剩下的问题是如何在命令行中实现这一点(甚至更好的命令行->netsh->winhttp)?
回答by Chinmay
If you are using Microsoft windows environment then you can set a variable named HTTP_PROXY
, FTP_PROXY
, or HTTPS_PROXY
depending on the requirement.
如果您使用的是Microsoft Windows环境,那么你可以设置一个命名变量HTTP_PROXY
,FTP_PROXY
或HTTPS_PROXY
根据要求。
I have used following settings for allowing my commands at windows command prompt to use the browser proxy to access internet.
我使用了以下设置来允许我在 Windows 命令提示符下的命令使用浏览器代理访问互联网。
set HTTP_PROXY=http://proxy_userid:proxy_password@proxy_ip:proxy_port
The parameters on right must be replaced with actual values.
右侧的参数必须替换为实际值。
Once the variable HTTP_PROXY
is set, all our subsequent commands executed at windows command prompt will be able to access internet through the proxy along with the authentication provided.
一旦HTTP_PROXY
设置了变量,我们在 windows 命令提示符下执行的所有后续命令都将能够通过代理以及提供的身份验证访问 Internet。
Additionally if you want to use ftp and https as well to use the same proxy then you may like to the following environment variables as well.
此外,如果您还想使用 ftp 和 https 来使用相同的代理,那么您可能还喜欢以下环境变量。
set FTP_PROXY=%HTTP_PROXY%
set HTTPS_PROXY=%HTTP_PROXY%
回答by overflowed
IE can set username and password proxies, so maybe setting it there and import does work
IE 可以设置用户名和密码代理,所以也许在那里设置并导入确实有效
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d name:port
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyUser /t REG_SZ /d username
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyPass /t REG_SZ /d password
netsh winhttp import proxy source=ie
回答by Adam Burley
The best way around this is (and many other situations) in my experience, is to use cntlmwhich is a local no-authentication proxy which points to a remote authentication proxy. You can then just set WinHTTP to point to your local CNTLM (usually localhost:3128), and you can set CNTLM itself to point to the remote authentication proxy. CNTLM has a "magic NTLM dialect detection" option which generates password hashes to be put into the CNTLM configuration files.
根据我的经验,解决此问题的最佳方法(以及许多其他情况)是使用cntlm,它是一个指向远程身份验证代理的本地无身份验证代理。然后您可以将 WinHTTP 设置为指向您的本地 CNTLM(通常是 localhost:3128),并且您可以将 CNTLM 本身设置为指向远程身份验证代理。CNTLM 有一个“神奇的 NTLM 方言检测”选项,它生成要放入 CNTLM 配置文件的密码哈希。
回答by Adasiek
cmd
指令
Tunnel all your internet traffic through a socks proxy:
通过socks代理隧道传输您的所有互联网流量:
netsh winhttp set proxy proxy-server="socks=localhost:9090" bypass-list="localhost"
View the current proxy settings:
查看当前的代理设置:
netsh winhttp show proxy
Clear all proxy settings:
清除所有代理设置:
netsh winhttp reset proxy