我正在使用 ADB 命令
adb shell settings put global http_proxy <ip>:<port>
效果非常好。
但是如果代理受用户名和密码保护,我无法登录代理
如果你知道什么请帮助我。
我做了一些调查并找到了正确的设置来通过 adb 启用带有身份验证的 http 代理:
adb shell settings put global http_proxy 192.168.225.100:3128
adb shell settings put global global_http_proxy_host 192.168.225.100
adb shell settings put global global_http_proxy_port 3128
adb shell settings put global global_http_proxy_username foo
adb shell settings put global global_http_proxy_password bar
并禁用代理:
adb shell settings delete global http_proxy
adb shell settings delete global global_http_proxy_host
adb shell settings delete global global_http_proxy_port
adb shell settings delete global global_http_proxy_username
adb shell settings delete global global_http_proxy_password
adb shell settings delete global global_http_proxy_exclusion_list
adb shell settings delete global global_proxy_pac_url
adb shell reboot
不幸的是,它在我的 Wear OS 手表上不起作用。也许你会更幸运。
为fish shell写了2个函数
此选项用于删除代理(无需重新启动设备)。
function adb_remove_proxy
# Get list of connected devices
set -l devices (adb devices | grep -v 'List of devices attached' | grep -v '^$' | cut -f1)
# Check if there are no devices connected
if test (count $devices) -eq 0
echo "No devices connected."
return 1
end
# If there is exactly one device, use that device
if test (count $devices) -eq 1
set -l device $devices[1]
else
# More than one device is connected, prompt the user to select one
echo "Multiple devices connected. Please select a device:"
for i in (seq (count $devices))
echo "$i) $devices[$i]"
end
echo -n "Enter the number of the device: "
read -l selection
set -l device $devices[$selection]
if test -z "$device"
echo "Invalid selection."
return 1
end
end
# Disable proxy settings on the selected device by setting http_proxy to :0
adb -s "$device" shell settings put global http_proxy ":0"
adb -s "$device" shell settings delete global global_http_proxy_host
adb -s "$device" shell settings delete global global_http_proxy_port
adb -s "$device" shell settings delete global global_http_proxy_username
adb -s "$device" shell settings delete global global_http_proxy_password
adb -s "$device" shell settings delete global global_http_proxy_exclusion_list
adb -s "$device" shell settings delete global global_proxy_pac_url
echo "Proxy settings disabled on device $device"
end
这用于设置设备代理
function adb_set_proxy
set -l ip $argv[1]
set -l port $argv[2]
set -l username "foo"
set -l password "bar"
if test -z "$ip" -o -z "$port"
echo "Usage: adb_set_proxy <IP> <PORT>"
return 1
end
# Get list of connected devices
set -l devices (adb devices | grep -v 'List of devices attached' | grep -v '^$' | cut -f1)
# Check if there are no devices connected
if test (count $devices) -eq 0
echo "No devices connected."
return 1
end
# If there is exactly one device, use that device
if test (count $devices) -eq 1
set -l device $devices[1]
else
# More than one device is connected, prompt the user to select one
echo "Multiple devices connected. Please select a device:"
for i in (seq (count $device))
echo "$i) $devices[$i]"
end
echo -n "Enter the number of the device: "
read -l selection
set -l device $devices[$selection]
if test -z "$device"
echo "Invalid selection."
return 1
end
end
# Set proxy settings on the selected device
adb -s "$device" shell settings put global http_proxy $ip:$port
adb -s "$device" shell settings put global global_http_proxy_host $ip
adb -s "$device" shell settings put global global_http_proxy_port $port
adb -s "$device" shell settings put global global_http_proxy_username $username
adb -s "$device" shell settings put global global_http_proxy_password $password
echo "Proxy set to $ip:$port on device $device with username $username and password $password"
end