Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
I
Ipv6 Proxy Switcher
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Ipv6 Proxy Switcher
Commits
eeb559ec
Commit
eeb559ec
authored
Apr 14, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
manual lookup
parent
16665cdc
Pipeline
#21236
failed with stages
in 93 minutes and 56 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
14 deletions
+31
-14
index.ts
index.ts
+31
-14
No files found.
index.ts
View file @
eeb559ec
...
@@ -3,6 +3,8 @@ import { Server, createConnection } from 'net';
...
@@ -3,6 +3,8 @@ import { Server, createConnection } from 'net';
import
{
hashAddress
}
from
'
./src/hash-address
'
;
import
{
hashAddress
}
from
'
./src/hash-address
'
;
import
{
createLogger
}
from
'
bunyan
'
;
import
{
createLogger
}
from
'
bunyan
'
;
import
{
Socket
}
from
'
net
'
;
import
{
Socket
}
from
'
net
'
;
import
Address
from
'
ipaddr.js
'
;
import
dns
from
'
dns
'
;
declare
module
'
net
'
{
declare
module
'
net
'
{
interface
Server
{
interface
Server
{
...
@@ -24,20 +26,34 @@ const log = createLogger({ name: 'switcher' });
...
@@ -24,20 +26,34 @@ const log = createLogger({ name: 'switcher' });
const
server
:
Server
=
createProxyServer
({
const
server
:
Server
=
createProxyServer
({
auth
:
true
,
auth
:
true
,
createProxyConnection
:
async
(
info
)
=>
{
createProxyConnection
:
async
(
info
)
=>
{
let
socket
:
Socket
;
const
src
:
Address
.
IPv4
|
Address
.
IPv6
=
info
.
socket
[
targetIpSym
]
;
log
.
info
(
log
.
info
(
`Connecting to
${
info
.
dstHost
}
:
${
info
.
dstPort
}
with
${
info
.
socket
[
targetIpSym
]
}
`
,
`Connecting to
${
info
.
dstHost
}
:
${
info
.
dstPort
}
with
${
src
?.
toString
()
}
`,
);
);
try
{
let socket: Socket;
socket
=
createConnection
({
if (src) {
host
:
info
.
dstHost
,
try {
port
:
info
.
dstPort
,
const lookup = await dns.promises.lookup(
localAddress
:
info
.
socket
[
targetIpSym
]
||
undefined
,
info.dstHost,
});
src.kind() === 'ipv4' ? 4 : 6,
}
catch
(
e
)
{
);
log
.
warn
(
socket = createConnection({
`Failed to connect to
${
info
.
dstHost
}
:
${
info
.
dstPort
}
, retrying direct connection:
${
e
}
`
,
host: lookup.address,
);
port: info.dstPort,
localAddress: src.toString(),
});
} catch (e) {
log.warn(
`
Remote
$
{
info
.
dstHost
}
does
not
support
$
{
src
.
kind
()},
fallback
to
direct
connect
.
`,
);
socket = createConnection({
host: info.dstHost,
port: info.dstPort,
});
}
} else {
socket = createConnection({
socket = createConnection({
host: info.dstHost,
host: info.dstHost,
port: info.dstPort,
port: info.dstPort,
...
@@ -56,8 +72,9 @@ server.on('proxy-auth', (socket, username, password, callback) => {
...
@@ -56,8 +72,9 @@ server.on('proxy-auth', (socket, username, password, callback) => {
return;
return;
}
}
const token = `
$
{
username
}:
$
{
password
}
`
;
const token = `
$
{
username
}:
$
{
password
}
`
;
socket
[
targetIpSym
]
=
hashAddress
(
process
.
env
.
CIDR
,
token
).
toString
();
const
address
=
hashAddress
(
process
.
env
.
CIDR
,
token
);
log
.
info
(
`Mapped
${
token
}
to
${
socket
[
targetIpSym
]}
`
);
socket
[
targetIpSym
]
=
address
;
log
.
info
(
`Mapped
${
token
}
to
${
address
.
toString
()}
`
);
callback
(
true
);
callback
(
true
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment