wget 指南 · 1 分钟阅读

如何使用wget与代理

wget从环境变量或其自己的.wgetrc读取代理,并通过专用标志获取凭据。这里是每种方法,以及一个需要知道的事情:wget支持HTTP代理,而不是SOCKS5。

wget 支持 HTTP 代理

关于 wget 和代理的最重要事实:经典的 wget 仅支持 HTTP 和 HTTPS 代理 — 它没有原生的 SOCKS5 支持。因此,使用 s4m 时,您需要将 wget 指向 HTTP 端点,proxy.s4m.online:3128,并使用您的 USER:PASS 进行身份验证。如果您特别需要 SOCKS5,可以使用 curl,或者使用像 proxychains 这样的 SOCKS 代理助手来包装 wget。

在 HTTP 代理中,wget 是灵活的。它遵循标准的 http_proxy、https_proxy 和 no_proxy 环境变量,从 ~/.wgetrc 读取持久设置,并通过 -e 以及 --proxy-user 和 --proxy-password 接受每个命令的覆盖。这使得为脚本下载全局设置代理变得简单,同时仍然可以为单次获取覆盖它。请参阅 proxy page 以获取端点信息,以及 proxy environment variables guide 以了解这些变量如何在 CLI 工具之间共享。

wget 代理,所有方法

环境变量、.wgetrc 和内联标志,均需认证。运行前请替换 USER:PASS。

bash
# --- Method 1: environment variables (per shell/session) ---
export http_proxy="http://USER:PASS@proxy.s4m.online:3128"
export https_proxy="http://USER:PASS@proxy.s4m.online:3128"
export no_proxy="localhost,127.0.0.1,.internal"
wget https://ftp.gnu.org/gnu/wget/wget-1.21.tar.gz

# --- Method 2: inline flags for one command ---
wget -e use_proxy=yes \
     -e https_proxy=proxy.s4m.online:3128 \
     --proxy-user=USER --proxy-password=PASS \
     https://example.com/file.iso

# --- Method 3: persistent ~/.wgetrc ---
cat > ~/.wgetrc <<'RC'
use_proxy = on
https_proxy = http://proxy.s4m.online:3128
http_proxy  = http://proxy.s4m.online:3128
proxy_user = USER
proxy_password = PASS
RC
wget https://example.com/file.iso   # reads ~/.wgetrc automatically

# --- Bypass the proxy for one download ---
wget --no-proxy https://internal.example/file

# --- Need SOCKS5? wget can't do it natively; wrap it: ---
# proxychains -f s4m.conf wget https://example.com/file.iso

使用哪种方法

将方法与下载的可重复性匹配。

一次性下载

使用内联标志:-e https_proxy=... 与 --proxy-user 和 --proxy-password。没有任何持久化,因此在共享机器上是安全的。

整个会话或脚本

导出http_proxy和https_proxy。在该shell中的每个wget(以及大多数其他CLI工具)共享出口,直到您取消设置它们。

每用户永久配置

将设置放入~/.wgetrc中,以便每次运行wget时都自动使用代理。适合你控制的专用下载盒。

需要 SOCKS5

wget 本身无法原生支持 SOCKS5。使用 curl 的 --socks5-hostname,或用指向 proxy.s4m.online:1080 的 proxychains 包裹 wget。

认证、no_proxy 和诚实

Credentials can go inline in the proxy URL (http://USER:PASS@host:3128) or in the dedicated --proxy-user / --proxy-password flags — the latter keeps the password out of the URL and out of some process listings. Always set no_proxy for internal hosts you never want routed through the proxy, and remember that inline flags override environment variables, which override ~/.wgetrc.

s4m 代理是经过身份验证的 数据中心 HTTP(和 SOCKS5)端点,按需计费 — 非常适合脚本下载、镜像和 CI 获取,您希望有一个稳定、隐藏的出口。它们不是住宅代理,因此阻止数据中心范围的网站可能会拒绝下载。要获得单一一致的地址,请添加一个 专用个人 IP。如果获取返回 407,您的凭据是错误的 — 请参阅 407 指南。从 免费列表 测试开放的 HTTP 代理,并使用 工具 验证端点。

FAQ

问题,已解答

wget可以使用SOCKS5代理吗?

不原生支持——经典的wget仅支持HTTP和HTTPS代理。将其指向s4m的HTTP端点,端口为3128,或者如果您需要SOCKS5,请使用curl的--socks5-hostname或用proxychains包装wget。

我如何永久设置wget代理?

在~/.wgetrc中添加use_proxy = on和http_proxy及https_proxy(以及proxy_user / proxy_password)。然后每次运行wget都会自动使用代理,直到您更改该文件。

我如何将代理凭据传递给 wget?

可以在代理 URL 中作为 http://USER:PASS@proxy.s4m.online:3128, 内联,或者使用 --proxy-user 和 --proxy-password 标志,这样可以将密码保留在 URL 之外。

我如何停止wget对某些主机使用代理?

设置 no_proxy 环境变量(以逗号分隔的主机列表)或在单个命令中传递 --no-proxy 以绕过内部或本地地址的代理。

代理您的下载

将 wget 指向 proxy.s4m.online:3128 上的经过认证的 HTTP 端点,并在隐藏的数据中心出口后进行镜像、获取和脚本。按需计费,专用 IP 可选。

人们通过搜索找到此页面

此页面回答的真实搜索短语 — 链接的短语打开详细覆盖它们的页面。