Android 设备命令行开代理

#!/bin/bash

echo "\n---------------- Support ------------------"
echo "设置默认代理    proxy set"
echo "设置自定义代理   proxy set ****:9090"
echo "删除代理        proxy clean"
echo "--------------------------------------------\n"

if [ "$1" == "set" ];then
    if [ -n "$2" ];then
        echo "设置自定义代理 $2"
        adb shell settings put global http_proxy $2
    else
        # 获取 IP
        ip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
        echo $ip
        count=$(echo $ip | tr ' ' '\n' | wc -l )
        if [ $count -gt 1 ];then
        echo "多个ip,请手动选择一个"
        exit
        fi
        default_proxy=${ip}":9090"
        echo "本机IP为: $default_proxy"
        echo "设置本机IP代理 $default_proxy"
        adb shell settings put global http_proxy $default_proxy
    fi
elif [ "$1" == "clean" ];then
    echo "清除代理成功"
    adb shell settings put global http_proxy :0
else
    echo "!!! 请输入合法的操作符 !!!"
fi

posted @ 2024-09-25 14:38  南风--  阅读(12)  评论(0编辑  收藏  举报