ubuntu-为wget使用代理
wget使用代理需要进行配置,而且目前不直接支持SOCKS5代理,需要运行辅助的软件,这里介绍有几种网上搜来的方法。不过,据试验,不是每种方法都好使,更具版本和网络环境而异,估计是这些软件都还不太成熟,只能说凑合了。
使用HTTP代理
方法一、在环境变量中设置代理
export http_proxy=http://127.0.0.1:8087
方法二、使用配置文件
为wget使用代理,可以直接修改/etc/wgetrc,也可以在主文件夹下新建.wgetrc,并编辑相应内容,本文采用后者。
将/etc/wgetrc中与proxy有关的几行复制到~/.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://127.0.0.1:8087/http_proxy = http://127.0.0.1:8087/ftp_proxy = http://127.0.0.1:8087/# If you do not want to use proxy at all, set this to off.use_proxy = on
这里 use_proxy = on 开启了代理,如果不想使用代理,每次都修改此文件未免麻烦,我们可以在命令中使用-Y参数来临时设置:
-Y, --proxy=on/off 打开或关闭代理
方法三、使用-e参数
wget本身没有专门设置代理的命令行参数,但是有一个"-e"参数,可以在命令行上指定一个原本出现在".wgetrc"中的设置。于是可以变相在命令行上指定代理:
-e, --execute=COMMAND 执行`.wgetrc'格式的命令
例如:
wget -c -r -np -k -L -p -e "http_proxy=http://127.0.0.1:8087" http://www.subversion.org.cn/svnbook/1.4/
这种方式对于使用一个临时代理尤为方便。
使用SOCKS5代理
首先,使用ssh开启一个socks通道:ssh -D 8001 remote_user@remote_ip
其次,
- 如果使用FireFox,在 “首选项-高级-网络”部分,设置 “连接-SOCKS主机”,输入127.0.0.1,端口8001,一定将DNS代理选中。
- 也可以在系统中设置SOCKS代理服务,然后在FireFox中设置 “使用系统代理”。
如果使用wget(wget目前不直接支持SOCKS代理),参考下面:
Socksify
In order to use with a SOCKS5 proxy from , you have to install the package in order to use the SOCKS_SERVER
option with the socksify
utility.
sudo pkg_add dante
Subsequently, you open an SSH connection in the background:
ssh -N -C -D1080 user@hostB &
And use wget through a SOCKS5 proxy through socksify:
env SOCKS_SERVER=127.0.0.1:1080 socksify wget http://website-C
Option :
Just pipe the file to stdout
on the server, and read it from stdin
on your workstation.
ssh -C user@hostB "wget -O- http://website-C" >> file-from-website-C
ProxyChains
using (which is the newer version of ).
- Download, compile, and optionally install .
- Create a
proxychains.conf
file in the current directory, or at~/.proxychains/proxychains.conf
, or at/etc/proxychains.conf
.- Alternatively, create one file anywhere else, or with another name, and specify if through
-f
command-line argument, or throughPROXYCHAINS_CONF_FILE
environment variable. - There is a available. The most relevant options are at the very end.
- Alternatively, create one file anywhere else, or with another name, and specify if through
-
In your
proxychains.conf
file, add:[ProxyList]socks5 127.0.0.1 1234
-
Run
ssh -D 1234 your_host_b
. This will make ssh listen on port 1234 on localhost, and use your remote host as a SOCKS proxy.- Alternatively, run
ssh -ND 1234 your_host_b
instead.-N
will prevent ssh from running any command on the remote server (i.e. it won't open a shell).
- Alternatively, run
- Run:
proxychains4 yourcommandhere yourparametershere
. See some examples:proxychains4 wget -O - http://ifconfig.co/
proxychains4 -q links http://ifconfig.co/
TSocks
- configure tsocks, uncomment every line, except three lines below, and
lqman:~$ sudo vim /etc/tsocks.conf server = 127.0.0.1 server_type = 5 server_port = 9999
- Try to download with wget
lqman:~$ tsocks wget google.com