命令行工具挂代理方式 git 代理 全局代理 1 2 3 git config --global http.proxy http: git config --global http.proxy 'socks5://127.0.0.1:1080' git config --global https.proxy 'socks5://127.0.0.1:1080'
清除配置 1 2 git config --global --unset http.proxy git config --global --unset https.proxy
临时代理 1 2 3 4 5 6 7 8 git clone -c http.proxy= http://127.0 .0.1 :8087 git clone -c sock.proxy= sock5://127.0 .0.1 :1086 http://XXX.gitALL_PROXY= socks5://127.0 .0.1 :1080 git clone xxx ALL_PROXY= socks5://127.0 .0.1 :1080 git push xxx
curl代理 1 curl -x 127.0.0.1:8087 google.com
设置 http 代理 1 curl -x HTTPS_PROXY://代理ip:端口 -OL https://github.com/alibaba/arthas/releases/download/arthas-all -4 .0 .4 /arthas-tunnel-server-4 .0 .4 -fatjar.jar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 curl -x 113.185.19.192:80 http://aiezu.com/test.php curl --proxy 113.185.19.192:80 http://aiezu.com/test.php curl -x http_proxy://113.185.19.192:80 http://aiezu.com/test.php curl -x HTTPS_PROXY://113.185.19.192:80 http://aiezu.com/test.php curl -x aiezu:123456 @113.185.19.192:80 http://aiezu.com/test.php curl -x 113.185.19.192:80 -U aiezu:123456 http://aiezu.com/test.php curl -x 113.185.19.192:80 --proxy-user aiezu:123456 http://aiezu.com/test.php curl -x 113.185.19.192:80 -U aiezu:123456 --proxy-ntlm http://aiezu.com/test.php curl -x http_proxy://aiezu:123456@113.185.19.192:80 http://aiezu.com/test.php
设置 socks 代理: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 curl --socks4 122.192.32.76:7280 http://aiezu.com/test.php curl -x socks4://122.192.32.76 :7280 http://aiezu.com/test.php curl --socks4a 122.192.32.76:7280 http://aiezu.com/test.php curl -x socks4a://122.192.32.76 :7280 http://aiezu.com/test.php curl --socks5 122.192.32.76:7280 -U aiezu:123456 http://aiezu.com/test.php curl -x socks5://aiezu :123456 @122.192.32.76:7280 http://aiezu.com/test.php curl -x socks5://aiezu :123456 @122.192.32.76:7280 --proxy-ntlm http://aiezu.com/test.php
参数说明:
-x 设置代理,格式为host[:port],port的缺省值为1080
*参考文档: *
wget代理 1 wget -Y on -e "http_proxy=http://127.0.0.1:8087" "google.com"
参数说明:
-Y 是否使用代理
-e 执行命令
CMD代理 通过命令行设置环境变量: 打开命令提示符(CMD)。 使用 set 命令临时设置代理:
1 2 set http_proxy =http://127.0.0.1:1080 set https_proxy =http://127.0.0.1:1080
powershell代理 以管理员的身份运行powershell:
1 Start-Process powershell -Verb runAs
设置代理
1 netsh winhttp set proxy "127.0.0.1:7890"
检查代理:
1 netsh winhttp show proxy
测试连接:
1 2 3 4 5 iwr -Uri https: # or iwr -Uri https:
关闭proxy:
1 netsh winhttp reset proxy
bash终端设置代理 1 2 export http_proxy ='http://localhost:8118' export https_proxy ='http://localhost:8118'
临时取消代理:
1 2 3 unset http_proxyunset https_proxy
git bash 终端设置代理 1 export https_proxy =socks5://127.0.0.1:1080
众所周知 Github DNS 被污染了,所有有时候下载十分困难,LazyVim 基本上所有的东西都托管在 Github 上,所以我们其实不用梯子也可以很完美的安装好 LazyVim,用代理就行。 我喜欢用 GitHub Proxy 这个代理,也有其他代理,大家可以自行找寻。
我们打开一个终端,输入:
1 git config --global url."https://mirror.ghproxy.com/https://github.com/" .insteadof "https://github.com/"
这样就可以让 GitHub Proxy 代理 GitHub 的 git clone , wget , curl 了。一般来说,这种 Github 代理都不会代理 ssh 协议,所以不会影响 ssh 访问 Github,另外其实 ssh 也没有被污染。
取消也很简单,首先我们看一下 git 的设置列表:
就可以看到 Git 的一些设置
也许可以看到有这么一项:
1 url.https: //mirror.ghproxy.com/https ://github .com/.insteadof=https: //github.com/
加入想取消这一项,就输入等号前面的内容:
1 git config --global --unset url.https: //mirror.ghproxy.com/https ://github .com/.insteadof
socks5转http代理 目标: 定制socks5代理转发
1 2 3 4 5 6 7 |====>| |====>| |====>| 浏览器| |Privoxy| |SOCKS代理| |目标网站 |<====| |<====| |<====| |此阶段是 | |此阶段是 | |此阶段是 | |HTTP | |SOCKS| |HTTP |
privoxy简介
Privoxy 是一个代理软件。支持的平台非常多,了解更多
借由 Privoxy,我们可以控制出去的请求,还可以改写返回的响应。不必要的请求 – 比如视频广告的地址、图片广告的地址,我们可以直接 block 掉;不必要的响应内容 – 比如页面中的文字广告,我们可以借由 filter 过滤掉,不让它们在浏览器页面上显示。 – 摘自: https://www.cnblogs.com/hongdada/p/10787924.html
下载地址:
Download Address
windows平台 windows privoxy安装目录说明:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 PS D:\Program Files (x86)\Privoxy> tree /f 卷 软件 的文件夹 PATH 列表 卷序列号为 0003 -DE55 D:. │ AUTHORS.txt │ config.txt ## 主配置文件 │ default .action │ default .filter │ LICENSE.txt │ match-all .action │ privoxy.exe │ privoxy.log │ privoxy_uninstall.exe │ README.txt │ trust.txt │ user .action │ user .filter
在配置文件config.txt中添加如下配置:
代理的IP地址与监听端口:
1 listen -address 127.0.0.1:8118
配置转发请求的代理IP地址与监听端口:
1 forward -socks5 / 127.0.0.1:1080 .
linux平台 系统环境
笔者的系统版本为: ubuntu20.4 笔者的socks代理为: 127.0.0.1:1080 使用的代理工具为: clashx + 某供应商提供的trojan机场 or ssh -D + 自建trojan机场
笔者自己用于备份内容ssh -D 挂代理脚本:
版本一:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #!/usr/bin/bash PID=$(ps aux|grep ssh|grep fgnTN|grep -v grep |awk '{print $2}' )echo $PID if [ $? -eq 0 -a ! -z "$PID " ]then echo "SSH Proxy server is on..." else echo "SSH Proxy server is death..." ssh -fgnTN -D 7079 yourusernam@yourhostname if [ $? -eq 0 ] then echo "SSH Proxy Service restart successd." else echo "SSH Proxy Service restart failed." fi fi
版本二:
笔者的脚本目录如下:
1 2 3 4 ➜ scripts tree -L 1. ├── proxy_login.sh ├── ssh_ proxy.sh
proxy_login.sh负责自动登录代理服务器ssh_proxy.sh 负责登录重启的逻辑
附件:
proxy_login.sh 脚本源码:
1 2 3 4 5 6 7 #!/usr/bin/expect set password "123456789@" spawn ssh -fgnTN -D 1080 installer@shop .foch.tk expect "installer@shop.foch.tk's password:" send "$password" expect eof interact
proxy_login.sh脚本的环境依赖
安装 expect apt-get install expect
代码注释
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 //这一行告诉操作系统脚本里的代码使用哪一个shell来执行。这里的expect其实和linux下的bash、windows下的cmd是一类东西。 //set 的功能是给参数赋值,这里设置的是超时时间,计时单位是:秒 。timeout -1 为永不超时set timeout 30 //expect脚本可以接受从bash传递过来的参数.可以使用[lindex $argv n]获得,n从0 开始,分别表示第一个,第二个,第三个....参数。[lrange $argv 0 0 ]表示第1 个参数,[lrange $argv 0 4 ]为第一个到第五个参数。set ipaddr [lrange $argv 0 0 ]set passwd "password" //spawn是进入expect环境后才可以执行的expect内部命令,功能是给ssh运行进程加个壳,用来传递交互指令。 spawn ssh root@$ipaddr //expect也是expect的一个内部命令,功能是判断上次输出结果里是否包含“password:”的字符串,如果有则立即返回,否则就等待一段时间后返回,这里等待时长就是前面设置的30 秒 expect "password:" //send的功能是执行交互动作,与手工输入密码的动作等效。命令字符串结尾别忘记加上“\r”。 send "$passwd\r" //expect命令结束 expect eof //执行完成后保持交互状态,把控制权交给控制台,这个时候就可以手工操作了。如果没有这一句登录完成后会退出,而不是留在远程终端上。如果你只是登录过去执行 interact
ssh_proxy.sh脚本源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #!/usr/bin/bash PID=$(ps aux|grep ssh|grep fgnTN|grep -v grep |awk '{print $2}' )echo $PID if [ $? -eq 0 -a ! -z "$PID " ]then echo "SSH Proxy server is on..." else echo "SSH Proxy server is death..." ./proxy_login.sh if [ $? -eq 0 ] then echo "SSH Proxy Service restart successd." else echo "SSH Proxy Service restart failed." fi fi
安装privoxy
1 sudo apt install privoxy
更改privoxy配置
1 sudo vi /etc/privoxy/config
在 froward-socks4下面添加一条socks5的,地址是127.0.0.1:1080。注意最后有一个.
1 forward -socks5 / 127.0.0.1:1080 .
重启privoxy服务
1 sudo systemctl restart privoxy.serivce
或者
1 sudo service privoxy restart
测试
1 2 3 dantefung@WIN -RL03VFUMQFV :/mnt/d/scripts $ ./ssh_proxy.sh dantefung@WIN -RL03VFUMQFV :/mnt/d/scripts $ export http_proxy='http://127.0.0.1:8118' dantefung@WIN -RL03VFUMQFV :/mnt/d/scripts $ curl -I www.google.com
期望结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 HTTP/1.1 200 OKContent-Type : text/html; charset=ISO-8859-1P3P : CP="This is not a P3P policy! See g.co/p3phelp for more info."Date : Thu, 17 Feb 2022 17:23:08 GMTServer : gwsX-XSS-Protection : 0X-Frame-Options : SAMEORIGINTransfer-Encoding : chunkedExpires : Thu, 17 Feb 2022 17:23:08 GMTCache-Control : privateSet-Cookie : 1P_JAR=2022-02-17-17; path=/; domain=.google.com; SecureSet-Cookie : NID=511=pcqU1X_oEh95me7ZnpKgUNGTmzSvSRIizVdUHVZTDZGQBwiyLtRMKW1ZokdQsczrA0TeX8EmEV2OpihlqPgK-6-JAw8ZmQrcPYcFyfbEliFd2PxPdZOPZ2A9M_svTXEITKNtoW_1k6t3tViNObjVly-IxFJxPApfaAg92qrK-3k; path=/; domain=.google.com; HttpOnlyProxy-Connection : keep-alive
Reference