惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
量子位
aimingoo的专栏
aimingoo的专栏
V
V2EX
Vercel News
Vercel News
B
Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
TaoSecurity Blog
TaoSecurity Blog
N
News and Events Feed by Topic
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
S
Secure Thoughts
U
Unit 42
博客园 - 叶小钗
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
Help Net Security
Help Net Security
S
Security Affairs
Microsoft Security Blog
Microsoft Security Blog
W
WeLiveSecurity
博客园 - Franky
Forbes - Security
Forbes - Security
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Schneier on Security
Schneier on Security
I
InfoQ
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Webroot Blog
Webroot Blog
AWS News Blog
AWS News Blog
Last Week in AI
Last Week in AI
Security Archives - TechRepublic
Security Archives - TechRepublic
C
CERT Recently Published Vulnerability Notes
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
Lohrmann on Cybersecurity
SecWiki News
SecWiki News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
J
Java Code Geeks

楚天乐的全栈之路

procrastinated单词终极指南:发音/中文解释/英文解释/词源/例句全解 | myxtea学英语 - 楚天乐的全栈之路 Vocabulary: Prolific - 楚天乐的全栈之路 DCT离散余弦变换和JPEG 压缩算法 - 楚天乐的全栈之路 c语言float和bytes array转换 - 楚天乐的全栈之路 地图找出口算法python实现 - 楚天乐的全栈之路 使用Vault管理服务器各种密码 - 楚天乐的全栈之路 windows环境pip无法安装dlib库的终极解决 - 楚天乐的全栈之路 写个dockerfile自动部署hugo - 楚天乐的全栈之路 php中__METHOD__和_FUNCTION__的区别 - 楚天乐的全栈之路
Windows WLS2使用本机ss代理访问github - 楚天乐的全栈之路
2022-06-04 · via 楚天乐的全栈之路

关键问题

WSL每次启动ip不一样,所以不能用静态方法设置http代理。
WSL会把宿主ip地址写入

获得当前宿主ip地址的方法

cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'

手动设置代理的方法

$ cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'
172.29.176.1

$ export https_proxy="http://172.29.190.80:10000"

# 下载github库
$ wget https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/face_checkpoints.zip
--2022-06-05 01:46:58--  https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/face_checkpoints.zip
正在连接 172.29.176.1:10000... 已连接。
已发出 Proxy 请求,正在等待回应... 302 Found
位置:https://objects.githubusercontent.com/github-production-release-asset-2e65be/274594200/49cb1e00-e34c-11eb-82bf-3c592a7d16da?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220604%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220604T174658Z&X-Amz-Expires=300&X-Amz-Signature=5ce75d01ba6ee4cb9c9ca3190282bb603552cc90a8e9cb64797eb9e19e6cc6ba&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=274594200&response-content-disposition=attachment%3B%20filename%3Dface_checkpoints.zip&response-content-type=application%2Foctet-stream [跟随至新的 URL]
--2022-06-05 01:46:58--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/274594200/49cb1e00-e34c-11eb-82bf-3c592a7d16da?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220604%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220604T174658Z&X-Amz-Expires=300&X-Amz-Signature=5ce75d01ba6ee4cb9c9ca3190282bb603552cc90a8e9cb64797eb9e19e6cc6ba&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=274594200&response-content-disposition=attachment%3B%20filename%3Dface_checkpoints.zip&response-content-type=application%2Foctet-stream
正在连接 172.29.176.1:10000... 已连接。
已发出 Proxy 请求,正在等待回应... 200 OK
长度: 684354563 (653M) [application/octet-stream]
正在保存至: ‘face_checkpoints.zip’

face_checkpoints.zip                                     100%[================================================================================================================================>] 652.65M  3.68MB/s    用时 2m 41s

2022-06-05 01:49:40 (4.06 MB/s) - 已保存 ‘face_checkpoints.zip’ [684354563/684354563])

启动时候自动设置的方法

脚本/usr/bin/proxy.sh, 记得替换成自己本机代理端口

#!/bin/sh
hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
wslip=$(hostname -I | awk '{print $1}')
port=10000

PROXY_HTTP="http://${hostip}:${port}"

set_proxy(){
    export http_proxy="${PROXY_HTTP}"
    export HTTP_PROXY="${PROXY_HTTP}"

    export https_proxy="${PROXY_HTTP}"
    export HTTPS_proxy="${PROXY_HTTP}"
}

unset_proxy(){
    unset http_proxy
    unset HTTP_PROXY
    unset https_proxy
    unset HTTPS_PROXY
}

test_setting(){
    echo "Host ip:" ${hostip}
    echo "WSL ip:" ${wslip}
    echo "Current proxy:" $https_proxy
}

if [ "$1" = "set" ]
then
    set_proxy

elif [ "$1" = "unset" ]
then
    unset_proxy

elif [ "$1" = "test" ]
then
    test_setting
else
    echo "Unsupported arguments."
fi

需要使用代理时

source proxy.sh set

取消代理

source proxy.sh unset

参考链接

https://zinglix.xyz/2020/04/18/wsl2-proxy/