mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-23 16:38:34 +08:00
31
_worker.js
31
_worker.js
@@ -1,5 +1,6 @@
|
||||
import { connect } from "cloudflare:sockets";
|
||||
let config_JSON, 反代IP = '', 启用SOCKS5反代 = null, 启用SOCKS5全局反代 = false, 我的SOCKS5账号 = '', parsedSocks5Address = {};
|
||||
let 缓存反代IP, 缓存反代解析数组, 缓存反代数组索引 = 0;
|
||||
let SOCKS5白名单 = ['*tapecontent.net', '*cloudatacdn.com', '*loadshare.org', '*cdn-centaurus.com', 'scholar.google.com'];
|
||||
const Pages静态页面 = 'https://edt-pages.github.io';
|
||||
///////////////////////////////////////////////////////主程序入口///////////////////////////////////////////////
|
||||
@@ -498,21 +499,28 @@ function 解析魏烈思请求(chunk, token) {
|
||||
return { hasError: false, addressType, port, hostname, isUDP, rawIndex: addrValIdx + addrLen, version };
|
||||
}
|
||||
async function forwardataTCP(host, portNum, rawData, ws, respHeader, remoteConnWrapper) {
|
||||
console.log(JSON.stringify({ configJSON: { 目标地址: host, 目标端口: portNum, 反代IP: 反代IP, 代理类型: 启用SOCKS5反代, 全局代理: 启用SOCKS5全局反代, 代理账号: 我的SOCKS5账号 } }));
|
||||
console.log(`[TCP转发] 目标: ${host}:${portNum} | 反代IP: ${反代IP} | 反代类型: ${启用SOCKS5反代 || 'proxyip'} | 全局: ${启用SOCKS5全局反代 ? '是' : '否'}`);
|
||||
async function connectDirect(address, port, data, 所有反代数组 = null) {
|
||||
let remoteSock;
|
||||
if (所有反代数组 && 所有反代数组.length > 0) {
|
||||
const 打乱后数组 = [...所有反代数组].sort(() => Math.random() - 0.5);
|
||||
const 最大尝试次数 = Math.min(8, 打乱后数组.length);
|
||||
for (let i = 0; i < 最大尝试次数; i++) {
|
||||
const [反代地址, 反代端口] = 打乱后数组[i];
|
||||
const 最大尝试次数 = 缓存反代数组索引 + Math.min(8, 所有反代数组.length);
|
||||
for (; 缓存反代数组索引 < 最大尝试次数; 缓存反代数组索引++) {
|
||||
const [反代地址, 反代端口] = 所有反代数组[缓存反代数组索引 % 所有反代数组.length];
|
||||
try {
|
||||
console.log(`[反代连接] 尝试连接到: ${反代地址}:${反代端口} (索引: ${缓存反代数组索引})`);
|
||||
remoteSock = connect({ hostname: 反代地址, port: 反代端口 });
|
||||
// 等待TCP连接真正建立,设置1秒超时
|
||||
await Promise.race([
|
||||
remoteSock.opened,
|
||||
new Promise((_, reject) => setTimeout(() => reject(new Error('连接超时')), 1000))
|
||||
]);
|
||||
const testWriter = remoteSock.writable.getWriter();
|
||||
await testWriter.write(data);
|
||||
testWriter.releaseLock();
|
||||
console.log(`[反代连接] 成功连接到: ${反代地址}:${反代端口}`);
|
||||
return remoteSock;
|
||||
} catch (err) {
|
||||
console.log(`[反代连接] 连接失败: ${反代地址}:${反代端口}, 错误: ${err.message}`);
|
||||
try { remoteSock?.close?.(); } catch (e) { }
|
||||
continue;
|
||||
}
|
||||
@@ -853,7 +861,7 @@ async function MD5MD5(文本) {
|
||||
}
|
||||
|
||||
function 随机路径() {
|
||||
const 常用路径目录 = ["#", "about", "account", "acg", "act", "activity", "ad", "admin", "ads", "ajax", "album", "albums", "anime", "api", "app", "apps", "archive", "archives", "article", "articles", "ask", "auth", "avatar", "bbs", "bd", "blog", "blogs", "book", "books", "bt", "buy", "cart", "category", "categories", "cb", "channel", "channels", "chat", "china", "city", "class", "classify", "clip", "clips", "club", "cn", "code", "collect", "collection", "comic", "comics", "community", "company", "config", "contact", "content", "course", "courses", "cp", "data", "detail", "details", "dh", "directory", "discount", "discuss", "dl", "dload", "doc", "docs", "document", "documents", "doujin", "download", "downloads", "drama", "edu", "en", "ep", "episode", "episodes", "event", "events", "f", "faq", "favorite", "favourites", "favs", "feedback", "file", "files", "film", "films", "forum", "forums", "friend", "friends", "game", "games", "gif", "go", "go.html", "go.php", "group", "groups", "help", "home", "hot", "htm", "html", "image", "images", "img", "index", "info", "intro", "item", "items", "ja", "jp", "jump", "jump.html", "jump.php", "jumping", "knowledge", "lang", "lesson", "lessons", "lib", "library", "link", "links", "list", "live", "lives", "login", "logout", "m", "mag", "magnet", "mall", "manhua", "map", "member", "members", "message", "messages", "mobile", "movie", "movies", "music", "my", "new", "news", "note", "novel", "novels", "online", "order", "out", "out.html", "out.php", "outbound", "p", "page", "pages", "pay", "payment", "pdf", "photo", "photos", "pic", "pics", "picture", "pictures", "play", "player", "playlist", "post", "posts", "product", "products", "program", "programs", "project", "qa", "question", "rank", "ranking", "read", "readme", "redirect", "redirect.html", "redirect.php", "reg", "register", "res", "resource", "retrieve", "sale", "search", "season", "seasons", "section", "seller", "series", "service", "services", "setting", "settings", "share", "shop", "show", "shows", "site", "soft", "sort", "source", "special", "star", "stars", "static", "stock", "store", "stream", "streaming", "streams", "student", "study", "tag", "tags", "task", "teacher", "team", "tech", "temp", "test", "thread", "tool", "tools", "topic", "topics", "torrent", "trade", "travel", "tv", "txt", "type", "u", "upload", "uploads", "url", "urls", "user", "users", "v", "version", "video", "videos", "view", "vip", "vod", "watch", "web", "wenku", "wiki", "work", "www", "zh", "zh-cn", "zh-tw", "zip"];
|
||||
const 常用路径目录 = ["about", "account", "acg", "act", "activity", "ad", "ads", "ajax", "album", "albums", "anime", "api", "app", "apps", "archive", "archives", "article", "articles", "ask", "auth", "avatar", "bbs", "bd", "blog", "blogs", "book", "books", "bt", "buy", "cart", "category", "categories", "cb", "channel", "channels", "chat", "china", "city", "class", "classify", "clip", "clips", "club", "cn", "code", "collect", "collection", "comic", "comics", "community", "company", "config", "contact", "content", "course", "courses", "cp", "data", "detail", "details", "dh", "directory", "discount", "discuss", "dl", "dload", "doc", "docs", "document", "documents", "doujin", "download", "downloads", "drama", "edu", "en", "ep", "episode", "episodes", "event", "events", "f", "faq", "favorite", "favourites", "favs", "feedback", "file", "files", "film", "films", "forum", "forums", "friend", "friends", "game", "games", "gif", "go", "go.html", "go.php", "group", "groups", "help", "home", "hot", "htm", "html", "image", "images", "img", "index", "info", "intro", "item", "items", "ja", "jp", "jump", "jump.html", "jump.php", "jumping", "knowledge", "lang", "lesson", "lessons", "lib", "library", "link", "links", "list", "live", "lives", "m", "mag", "magnet", "mall", "manhua", "map", "member", "members", "message", "messages", "mobile", "movie", "movies", "music", "my", "new", "news", "note", "novel", "novels", "online", "order", "out", "out.html", "out.php", "outbound", "p", "page", "pages", "pay", "payment", "pdf", "photo", "photos", "pic", "pics", "picture", "pictures", "play", "player", "playlist", "post", "posts", "product", "products", "program", "programs", "project", "qa", "question", "rank", "ranking", "read", "readme", "redirect", "redirect.html", "redirect.php", "reg", "register", "res", "resource", "retrieve", "sale", "search", "season", "seasons", "section", "seller", "series", "service", "services", "setting", "settings", "share", "shop", "show", "shows", "site", "soft", "sort", "source", "special", "star", "stars", "static", "stock", "store", "stream", "streaming", "streams", "student", "study", "tag", "tags", "task", "teacher", "team", "tech", "temp", "test", "thread", "tool", "tools", "topic", "topics", "torrent", "trade", "travel", "tv", "txt", "type", "u", "upload", "uploads", "url", "urls", "user", "users", "v", "version", "video", "videos", "view", "vip", "vod", "watch", "web", "wenku", "wiki", "work", "www", "zh", "zh-cn", "zh-tw", "zip"];
|
||||
const 随机数 = Math.floor(Math.random() * 3 + 1);
|
||||
const 随机路径 = 常用路径目录.sort(() => 0.5 - Math.random()).slice(0, 随机数).join('/');
|
||||
return `/${随机路径}`;
|
||||
@@ -1316,6 +1324,7 @@ function sha224(s) {
|
||||
}
|
||||
|
||||
async function 解析地址端口(proxyIP) {
|
||||
if (!缓存反代IP || !缓存反代解析数组 || 缓存反代IP !== proxyIP) {
|
||||
proxyIP = proxyIP.toLowerCase();
|
||||
async function DoH查询(域名, 记录类型) {
|
||||
try {
|
||||
@@ -1390,11 +1399,11 @@ async function 解析地址端口(proxyIP) {
|
||||
所有反代数组 = [[地址, 端口]];
|
||||
}
|
||||
}
|
||||
|
||||
return 所有反代数组;
|
||||
// low
|
||||
const [选中地址, 选中端口] = 所有反代数组[Math.floor(Math.random() * 所有反代数组.length)];
|
||||
return [选中地址, 选中端口];
|
||||
缓存反代解析数组 = 所有反代数组;
|
||||
console.log(`[反代解析] 解析完成 总数: ${缓存反代解析数组.length}个\n${缓存反代解析数组.map(([ip, port], index) => `${index + 1}. ${ip}:${port}`).join('\n')}`);
|
||||
缓存反代IP = proxyIP;
|
||||
} else console.log(`[反代解析] 读取缓存 总数: ${缓存反代解析数组.length}个\n${缓存反代解析数组.map(([ip, port], index) => `${index + 1}. ${ip}:${port}`).join('\n')}`);
|
||||
return 缓存反代解析数组;
|
||||
}
|
||||
|
||||
async function SOCKS5可用性验证(代理协议 = 'socks5', 代理参数) {
|
||||
|
||||
Reference in New Issue
Block a user