Skip to content

Commit 3cba001

Browse files
authored
修复反代IP问题
1 parent 38b89c5 commit 3cba001

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

_worker.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77

88
let id = atob('ZWM4NzJkOGYtNzJiMC00YTA0LWI2MTItMDMyN2Q4NWUxOGVk');
99

10-
let pnum = atob('NDQz');
1110
let paddrs = [
1211
atob('cHJveHlpcC5hbWNsdWJzLmNhbWR2ci5vcmc='),
1312
atob('cHJveHlpcC5hbWNsdWJzLmtvem93LmNvbQ==')
1413
];
15-
let paddr = paddrs[Math.floor(Math.random() * paddrs.length)];
1614
let pDomain = [];
1715

18-
let p64 = true;
16+
let p64 = false;
1917
let p64DnUrl = atob('aHR0cHM6Ly8xLjEuMS4xL2Rucy1xdWVyeQ==');
2018
let p64Prefix = atob('MjYwMjpmYzU5OmIwOjY0Ojo=');
2119
let p64Domain = [];
@@ -58,7 +56,9 @@ export default {
5856
id = (kvData.kv_id || ID || id).toLowerCase();
5957
log(`[fetch]--> id = ${id}`);
6058

59+
let paddr = paddrs[Math.floor(Math.random() * paddrs.length)];
6160
paddr = url.searchParams.get('PADDR') || PADDR || paddr;
61+
let pnum = atob('NDQz');
6262
if (paddr) {
6363
const [ip, port] = paddr.split(':');
6464
paddr = ip;
@@ -86,9 +86,9 @@ export default {
8686

8787
if (request.headers.get('Upgrade') === 'websocket') {
8888
if (prType === xorDe(dataTypeTr, 'datatype')) {
89-
return await websvcExecutorTr(request);
89+
return await websvcExecutorTr(request, paddr, pnum);
9090
}
91-
return await websvcExecutor(request);
91+
return await websvcExecutor(request, paddr, pnum);
9292
}
9393
switch (url.pathname.toLowerCase()) {
9494
case '/': {
@@ -240,7 +240,7 @@ function xorDe(b64, key) {
240240
return decoder.decode(out);
241241
}
242242

243-
async function getDomainToRouteX(addressRemote, portRemote, s5Enable, p64Flag = false) {
243+
async function getDomainToRouteX(addressRemote, portRemote, s5Enable, p64Flag = false, paddr, pnum) {
244244
let finalTargetHost = addressRemote;
245245
let finalTargetPort = portRemote;
246246
try {
@@ -1017,7 +1017,7 @@ async function show_kv_page(env) {
10171017
/** -------------------websvc logic-------------------------------- */
10181018
const WS_READY_STATE_OPEN = 1;
10191019
const WS_READY_STATE_CLOSING = 2;
1020-
async function websvcExecutor(request) {
1020+
async function websvcExecutor(request, paddr, pnum) {
10211021
const webSocketPair = new WebSocketPair();
10221022
const [client, webSocket] = Object.values(webSocketPair);
10231023
webSocket.accept();
@@ -1086,7 +1086,7 @@ async function websvcExecutor(request) {
10861086
return;
10871087
}
10881088

1089-
handleTPOut(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, channelResponseHeader, log, addressType);
1089+
handleTPOut(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, channelResponseHeader, log, addressType, paddr, pnum);
10901090
},
10911091
close() {
10921092
log(`readableWebSocketStream is close`);
@@ -1104,7 +1104,7 @@ async function websvcExecutor(request) {
11041104
});
11051105
}
11061106

1107-
async function websvcExecutorTr(request) {
1107+
async function websvcExecutorTr(request, paddr, pnum) {
11081108
const webSocketPair = new WebSocketPair();
11091109
const [client, webSocket] = Object.values(webSocketPair);
11101110
webSocket.accept();
@@ -1140,7 +1140,7 @@ async function websvcExecutorTr(request) {
11401140
throw new Error(message);
11411141
}
11421142

1143-
handleTPOut(remoteSocketWrapper, addressRemote, portRemote, rawClientData, webSocket, null, log, addressType);
1143+
handleTPOut(remoteSocketWrapper, addressRemote, portRemote, rawClientData, webSocket, null, log, addressType, paddr, pnum);
11441144
};
11451145

11461146
readableWebSocketStream.pipeTo(
@@ -1200,7 +1200,7 @@ function websvcStream(pipeServer, earlyDataHeader, log) {
12001200
return stream;
12011201
}
12021202

1203-
async function handleTPOut(remoteS, addressRemote, portRemote, rawClientData, pipe, channelResponseHeader, log, addressType) {
1203+
async function handleTPOut(remoteS, addressRemote, portRemote, rawClientData, pipe, channelResponseHeader, log, addressType, paddr, pnum) {
12041204

12051205
async function connectAndWrite(address, port, socks = false) {
12061206
const tcpS = socks ? await serviceCall(addressType, address, port, log) : connect({ hostname: address, port: port, servername: addressRemote });
@@ -1265,7 +1265,7 @@ async function handleTPOut(remoteS, addressRemote, portRemote, rawClientData, pi
12651265
}
12661266
}
12671267

1268-
const { finalTargetHost, finalTargetPort } = await getDomainToRouteX(addressRemote, portRemote, s5Enable, false);
1268+
const { finalTargetHost, finalTargetPort } = await getDomainToRouteX(addressRemote, portRemote, s5Enable, false, paddr, pnum);
12691269
const tcpS = await connectAndWrite(finalTargetHost, finalTargetPort, s5Enable ? true : false);
12701270
transferDataStream(tcpS, pipe, channelResponseHeader, finalStep, log);
12711271
}
@@ -1797,4 +1797,4 @@ function renderPage({ base64Title, suffix = '', heading, bodyContent }) {
17971797
</div>
17981798
</body>
17991799
</html>`;
1800-
}
1800+
}

0 commit comments

Comments
 (0)