Skip to content

Commit

Permalink
add use non 443 port as proxyIP
Browse files Browse the repository at this point in the history
  • Loading branch information
6Kmfi6HP committed Sep 21, 2024
1 parent 581cb9e commit 299acea
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,28 @@ ask question and cloudflare ips: [https://t.me/edtunnel](https://t.me/edtunnel)

3. Noneed add `nodejs_compat` at setting Compatibility flags

## How to use non 443 port as proxyIP

1. got to `https://proxyip.edtunnel.best/` paste your `ProxyIP:proxyport` and click `Check` button.
2. if `Proxy IP` is `true`, you can use this `ProxyIP:proxyport` as `ProxyIP`
3. if `Proxy IP` is `false`, you can see `Origin` is `443` this means the port can be accessed website.
4. edit worker `PROXYIP` variable example `211.230.110.231:50008`

Note: the proxyIP with port may not vaild some cloudflare site that use http only.

## How to change UUID

1. edit `wrangler.toml` file `UUID` variable(not recommended at public repo)
2. edit `UUID` in cloudflare dashboard secret enviroment variable (recommended)

## Support Environment Variables

| Variable | Required | Example | Description |
| -------------- | -------- | --------------------------------------- | ---------------------------------- |
| `UUID` | No | `12345678-1234-1234-1234-123456789012` | Unique identifier |
| `PROXYIP` | No | `1.1.1.1` or `cdn.xn--b6gac.eu.org` | Redirct cloudflare ips to ProxyIP |
| `SOCKS5` | No | `1.1.1.1:1080` or `user:pass@host:port` | SOCKS5 proxy cloudflare ips |
| `SOCKS5_RELAY` | No | `true` or `false` | Enable SOCKS5 relaying all traffic |
| Variable | Required | Example | Description |
| -------------- | -------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| `UUID` | No | `12345678-1234-1234-1234-123456789012` | Unique identifier |
| `PROXYIP` | No | `1.1.1.1` or `cdn.xn--b6gac.eu.org` or with port `1.1.1.1:9443` or `[2a01:4f8:c2c:123f:64:5:6810:c55a]:443` | Redirct cloudflare ips to ProxyIP |
| `SOCKS5` | No | `1.1.1.1:1080` or `user:pass@host:port` | SOCKS5 proxy cloudflare ips |
| `SOCKS5_RELAY` | No | `true` or `false` | Enable SOCKS5 relaying all traffic |

### Enviroment variable setting workers

Expand Down
29 changes: 18 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import { connect } from 'cloudflare:sockets';
// [Windows] Press "Win + R", input cmd and run: Powershell -NoExit -Command "[guid]::NewGuid()"
let userID = 'd342d11e-d424-4583-b36e-524ab1f0afa4';

const proxyIPs = ['cdn.xn--b6gac.eu.org', 'cdn-all.xn--b6gac.eu.org', 'workers.cloudflare.cyou'];
const proxyIPs = ['cdn.xn--b6gac.eu.org:443', 'cdn-all.xn--b6gac.eu.org:443', 'workers.cloudflare.cyou:443'];

// if you want to use ipv6 or single proxyIP, please add comment at this line and remove comment at the next line
let proxyIP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)];
// how to make sure the proxyIP with port is valid?
// go to https://proxyip.edtunnel.best/ , input your proxyIP:proxyPort, and click "Check" button
// if the port is valid, value "Proxy IP" is true, otherwise false and the value "Origin" must be 443
let proxyPort = proxyIP.includes(':') ? proxyIP.split(':')[1] : '443';

// use single proxyip instead of random
// let proxyIP = 'cdn.xn--b6gac.eu.org';
// ipv6 proxyIP example remove comment to use
Expand Down Expand Up @@ -38,10 +43,16 @@ export default {
try {
const { UUID, PROXYIP, SOCKS5, SOCKS5_RELAY } = env;
userID = UUID || userID;
proxyIP = PROXYIP || proxyIP;
socks5Address = SOCKS5 || socks5Address;
socks5Relay = SOCKS5_RELAY || socks5Relay;

if (PROXYIP) {
[proxyIP, proxyPort = '443'] = PROXYIP.split(':');
} else {
proxyPort = proxyIP.includes(':') ? proxyIP.split(':')[1] : '443';
proxyIP = proxyIP.split(':')[0];
}
console.log('ProxyIP:', proxyIP);
console.log('ProxyPort:', proxyPort);
if (socks5Address) {
try {
parsedSocks5Address = socks5AddressParser(socks5Address);
Expand Down Expand Up @@ -171,18 +182,15 @@ async function ProtocolOverWSHandler(request) {
if (hasError) {
// controller.error(message);
throw new Error(message); // cf seems has bug, controller.error will not end stream
// webSocket.close(1000, message);
return;
}
// if UDP but port not DNS port, close it
// Handle UDP connections for DNS (port 53) only
if (isUDP) {
if (portRemote === 53) {
isDns = true;
} else {
// controller.error('UDP proxy only enable for DNS which is port 53');
throw new Error('UDP proxy only enable for DNS which is port 53'); // cf seems has bug, controller.error will not end stream
return;
throw new Error('UDP proxy is only enabled for DNS (port 53)');
}
return; // Early return after setting isDns or throwing error
}
// ["version", "附加信息长度 N"]
const ProtocolResponseHeader = new Uint8Array([ProtocolVersion[0], 0]);
Expand Down Expand Up @@ -248,7 +256,6 @@ async function trojanOverWSHandler(request) {
portWithRandomLog = `${portRemote}--${Math.random()} tcp`;
if (hasError) {
throw new Error(message);
return;
}
handleTCPOutBound(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, log, addressType);
},
Expand Down Expand Up @@ -306,7 +313,7 @@ async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portR
if (enableSocks) {
tcpSocket = await connectAndWrite(addressRemote, portRemote, true);
} else {
tcpSocket = await connectAndWrite(proxyIP || addressRemote, portRemote);
tcpSocket = await connectAndWrite(proxyIP || addressRemote, proxyPort || portRemote);
}
// no matter retry success or not, close websocket
tcpSocket.closed.catch(error => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"deploy": "wrangler deploy",
"build": "wrangler deploy --dry-run",
"dev": "wrangler dev --remote",
"dev-local": "wrangler dev index.js --remote",
"obfuscate": "javascript-obfuscator _worker.js"
},
"author": "",
Expand Down
8 changes: 2 additions & 6 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ workers_dev = true

[vars]
# UUID = "d342d11e-d424-4583-b36e-524ab1f0afa4"
# PROXYIP = "1.2.3.4"
# DNS_RESOLVER_URL = "https://cloudflare-dns.com/dns-query"
# NODE_ID = "1"
# API_TOKEN = "example_dev_token"
# API_HOST = "api.v2board.com"
UUID = "1b6c1745-992e-4aac-8685-266c090e50ea,89b64978-6244-4bf3-bf64-67ade4ce5c8f,d342d11e-d424-4583-b36e-524ab1f0afa4"
PROXYIP = "211.230.110.231:50008"
UUID = "1b6c1745-992e-4aac-8685-266c090e50ea"

0 comments on commit 299acea

Please sign in to comment.