MCPcopy Create free account
hub / github.com/cmliu/CF-Workers-CheckProxyIP / parseTarget

Function parseTarget

_worker.js:203–230  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

201}
202
203function parseTarget(input) {
204 let host = String(input || '').split('#')[0].trim();
205 let port = 443;
206
207 if (host.startsWith('[')) {
208 const ipv6PortIndex = host.lastIndexOf(']:');
209 if (ipv6PortIndex !== -1) {
210 const maybePort = Number(host.slice(ipv6PortIndex + 2));
211 if (Number.isInteger(maybePort) && maybePort >= 1 && maybePort <= 65535) {
212 port = maybePort;
213 host = host.slice(0, ipv6PortIndex + 1);
214 }
215 }
216 return { host, port };
217 }
218
219 const colonMatches = host.match(/:/g) || [];
220 if (colonMatches.length === 1) {
221 const separatorIndex = host.lastIndexOf(':');
222 const maybePort = Number(host.slice(separatorIndex + 1));
223 if (Number.isInteger(maybePort) && maybePort >= 1 && maybePort <= 65535) {
224 port = maybePort;
225 host = host.slice(0, separatorIndex);
226 }
227 }
228
229 return { host, port };
230}
231
232function isIPv4(value) {
233 const parts = value.split('.');

Callers 1

handleResolveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected