Giter Site home page Giter Site logo

wsl_ip's Introduction

为WSL2配置Windows代理(可解决WSL2动态ip问题)

  1. 执行脚本(bash),可能需要管理员权限
bash <(curl -s https://raw.githubusercontent.com/Doraemonkeys/WSL_IP/master/install.sh)
  1. 按提示输入代理端口号(clash默认7890,v2ray默认10809)

image-20230509013613785

  1. 暂时关闭windows网络防火墙(只关闭公用网络就行)

image-20230509014017161

  1. 开启代理软件的允许来自局域网的连接选项

image-20230509014522847

  1. 重启终端/WSL2

  2. 在终端输入 proxy_on 即可开启代理,输入 proxy_off 关闭代理。

windows添加防火墙规则

重新开启windows防火墙后若能正常使用则跳过此步骤。

如何让Windows的代理作用于wsl2?

  1. 确定联网的进程

我们可以通过资源监视器->网络,去确定对应端口的进程名 xray.exe

img

然后,在任务管理器中右键单击 xray.exe,选择属性,获取其文件路径

img

  1. 添加防火墙规则

通过允许其他应用按钮,添加 xray.exe 到允许列表

img

原始脚本

function proxy_on() {
# 改成你的 http_proxy(局域网)端口号
export http_proxy="http://$(wslip):7890"
export https_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
echo -e "终端代理已开启,windows ip 为 $(wslip)"
if curl --silent --head --max-time 3 https://www.google.com/ | grep "HTTP.*200" > /dev/null; then
        echo "Google 连通性正常。"
else
        echo "无法连接到 Google。"
        unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY
        echo -e "终端代理已关闭。"
fi
}


function proxy_off(){
    unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY
    echo -e "终端代理已关闭。"
}

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

wsl_ip's People

Contributors

doraemonkeys avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.