我想wget
使用代理下载一些东西:
HTTP Proxy: 127.0.0.1
Port: 8080
代理不需要用户名和密码。
我怎样才能做到这一点?
对于系统的所有用户,通过/etc/wgetrc
或 仅对于带有~/.wgetrc
文件的用户:
use_proxy=yes
http_proxy=127.0.0.1:8080
https_proxy=127.0.0.1:8080
或通过-e
URL 后面的选项:
wget ... -e use_proxy=yes -e http_proxy=127.0.0.1:8080 ...
输入命令行:
$ export http_proxy=http://proxy_host:proxy_port
对于经过身份验证的代理,
$ export http_proxy=http://username:password@proxy_host:proxy_port
然后运行
$ wget fileurl
对于 https,只需使用 https_proxy 而不是 http_proxy。您也可以将这些行放在您的 ~/.bashrc 文件中,这样您就不需要每次都执行此操作。
以下可能的配置位于/etc/wgetrc
取消注释并使用...
# You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
#https_proxy = http://proxy.yoyodyne.com:18023/
#http_proxy = http://proxy.yoyodyne.com:18023/
#ftp_proxy = http://proxy.yoyodyne.com:18023/
# If you do not want to use proxy at all, set this to off.
#use_proxy = on
wget 在命令行中使用类似这样的环境变量可以工作:
export http_proxy=http://your_ip_proxy:port/
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export dns_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
在尝试了许多教程来在经过身份验证的代理后面配置我的 Ubuntu 16.04 LTS 之后,它使用了以下步骤:
编辑/etc/wgetrc
:
$ sudo nano /etc/wgetrc
取消注释这些行:
#https_proxy = http://proxy.yoyodyne.com:18023/
#http_proxy = http://proxy.yoyodyne.com:18023/
#ftp_proxy = http://proxy.yoyodyne.com:18023/
#use_proxy = on
更改http://proxy.yoyodyne.com:18023/
为http://username:password@domain:port/
重要提示:如果仍然不起作用,请检查您的密码是否包含特殊字符,例如
#
,@
, ... 如果是这种情况,请将它们转义(例如,替换passw@rd
为passw%40rd
)。
在 Ubuntu 12.x 中,我在 $HOME/.wgetrc 中添加了以下行
http_proxy = http://uname:passwd@proxy.blah.com:8080
use_proxy = 开启
在 Debian Linux 中,可以通过环境变量和 wgetrc 将 wget 配置为使用代理。在这两种情况下,用于 HTTP 和 HTTPS 连接的变量名称都是
http_proxy=hostname_or_IP:portNumber
https_proxy=hostname_or_IP:portNumber
请注意,文件 /etc/wgetrc 优先于环境变量,因此如果您的系统在那里配置了代理并且您尝试使用环境变量,它们似乎没有效果!
如果您只需要使用代理执行一次 wget,最简单的方法是使用这样的单行代码:
http_proxy=http://username:password@proxy_host:proxy_port wget http://fileurl
或使用 https 目标 URL:
https_proxy=http://username:password@proxy_host:proxy_port wget https://fileurl
在我的 ubuntu 中,遵循 $HOME/.wgetrc 中的行就可以了!
http_proxy = http://uname:passwd@proxy.blah.com:8080
use_proxy = 开启
export http_proxy=http://proxy_host:proxy_port/
export https_proxy=https://proxy_host:proxy_port/
或者
export http_proxy=http://username:password@proxy_host:proxy_port/
export https_proxy=https://username:password@proxy_host:proxy_port/
正如所有其他人在这里解释的那样,这些环境变量有助于传递代理。
注意:但请注意,如果密码包含任何特殊字符,则需要将其配置为%<hex_value_of_special_char>
.
示例:如果密码是pass#123
,需要按照pass%23123
上面的导出命令使用。
在 Windows 中——对于 Fiddler 来说——使用环境变量:
set http_proxy=http://127.0.0.1:8888
set https_proxy=http://127.0.0.1:8888
在文件~/.wgetrc或/etc/wgetrc中添加以下行(如果文件不存在则创建该文件):
http_proxy = http://[Proxy_Server]:[port]
https_proxy = http://[Proxy_Server]:[port]
ftp_proxy = http://[Proxy_Server]:[port]
欲了解更多信息,https://www.thegeekdiary.com/how-to-use-wget-to-download-file-via-proxy/
使用tsocks通过socks5代理启动 wget :
sudo apt install tsocks
配置 tsocks
# vi /etc/tsocks.conf
server = 127.0.0.1
server_type = 5
server_port = 1080
tsocks wget http://url_to_get