下载地址
切换ip.apk
目前仅支持豆芽代理官网:https://www.douyadaili.com/
配置图
按图配置后在豆芽网页底部生成后填入app即可一键切换,请注意添加白名单否则无网络。
单个ip时效最长60分钟。
代码开源,需要自取
"ui";
"auto";
"http";
// 加载存储的代理 API 地址
let storage = storages.create("proxy_storage");
let savedApiUrl = storage.get("proxyApiUrl", "");
ui.layout(
<vertical gravity="center">
<horizontal w="*" gravity="center_vertical">
<input id="ipInput" hint="输入代理API地址" w="280sp" text="{{savedApiUrl}}" />
</horizontal>
<horizontal w="*" gravity="center_vertical" marginTop="20sp">
<button id="ipSwitch" text="切换IP" w="*" />
</horizontal>
<horizontal w="*" gravity="center_vertical" marginTop="20sp">
<text text="当前IP地址: " w="auto" />
<text id="currentIp" text="null" w="auto" />
</horizontal>
<horizontal w="*" gravity="center_vertical" marginTop="10sp">
<text text="状态: " w="auto" />
<text id="status" text="null" w="auto" />
</horizontal>
<horizontal w="*" gravity="center_vertical" marginTop="10sp">
<text text="归属地: " w="auto" />
<text id="guishu" text="null" w="auto" />
</horizontal>
<horizontal w="*" gravity="center_vertical" marginTop="20sp">
<button id="clearProxy" text="清除系统代理" w="*" />
</horizontal>
</vertical>
);
// 设置当前IP地址的初始值
ui.currentIp.setText("192.168.1.1"); // 可以根据实际情况初始化
// 绑定切换IP按钮的点击事件
ui.ipSwitch.on("click", () => {
let apiUrl = ui.ipInput.getText().toString();
if (apiUrl) {
// 存储代理 API 地址
storage.put("proxyApiUrl", apiUrl);
// 清除现有代理
clearSystemProxy();
ui.status.setText("开始切换");
setNewIP(apiUrl);
} else {
ui.status.setText("请输入代理API地址");
}
});
// 绑定清除系统代理按钮的点击事件
ui.clearProxy.on("click", () => {
// 执行清除系统代理的函数
clearSystemProxy();
ui.status.setText("系统代理已清除");
});
// 清除系统代理的函数
function clearSystemProxy() {
try {
shell("settings put global http_proxy :0", true);
shell("settings put global https_proxy :0", true);
} catch (e) {
ui.status.setText("清除系统代理失败");
}
}
// 设置新的IP地址和获取归属地信息
function setNewIP(apiUrl) {
// 获取新的代理IP
http.get(apiUrl, {}, function(res) {
try {
let proxy = res.body.json();
// console.log(proxy);
if (proxy && proxy.data) {
let data = proxy.data[0]; // 你返回的是一个数组,使用第一个元素
let host = data.ip;
let port = data.port;
let gsd = `${data.city || ''} ${data.isp || ''}`;
if (host && port) {
let shellResult1 = shell("settings put global http_proxy " + host + ":" + port, true);
let shellResult2 = shell("settings put global global_http_proxy_host " + host, true);
let shellResult3 = shell("settings put global global_http_proxy_port " + port, true);
if (shellResult1.code === 0 && shellResult2.code === 0 && shellResult3.code === 0) {
ui.run(() => {
ui.currentIp.setText(host);
ui.status.setText("IP地址已切换");
ui.guishu.setText(gsd);
});
} else {
ui.run(() => ui.status.setText("设置代理失败"));
}
} else {
ui.run(() => ui.status.setText("获取到的代理IP格式无效"));
}
} else {
ui.run(() => ui.status.setText("未能获取到代理数据"));
}
} catch (e) {
ui.run(() => ui.status.setText("解析返回数据失败"));
console.error(e);
}
});
}
fdijki