This module provides a SOCKS5 proxy server with optional authentication and support for forwarding requests through an upstream SOCKS5 proxy.
- SOCKS5 proxy server with authentication
- Upstream SOCKS5 proxy support
- Automatic port allocation
- Error handling mechanisms
socksv5
socks
net
ipv6
ipv4
npm install socks5-proxy-server
(async () => {
const proxyServer = await app({ port: 1080, user: "test", password: "pass" });
console.log(
`Socks5 server running on localhost:${proxyServer.port}, ${
proxyServer.user && proxyServer.password ? `user:${proxyServer.user}, password:${proxyServer.password}` : "no authentication"
}`
);
})();
(async () => {
const proxyServer = await app({ port: 1080 });
console.log(
`Socks5 server running on localhost:${proxyServer.port}, ${
proxyServer.user && proxyServer.password ? `user:${proxyServer.user}, password:${proxyServer.password}` : "no authentication"
}`
);
})();
(async () => {
const proxyServer = await app({ user: "test", password: "pass" });
console.log(
`Socks5 server running on localhost:${proxyServer.port}, ${
proxyServer.user && proxyServer.password ? `user:${proxyServer.user}, password:${proxyServer.password}` : "no authentication"
}`
);
})();
(async () => {
const proxyServer = await app(
{ port: 1080, user: "test", password: "pass" },
{ hostProxy: "172.31.24.202", portProxy: 2001, userProxy: "gemink", passwordProxy: "proxys" }
);
console.log(
`Socks5 server running on localhost:${proxyServer.port}, ${
proxyServer.user && proxyServer.password ? `user:${proxyServer.user}, password:${proxyServer.password}` : "no authentication"
}`
);
})();
To stop the proxy server, you can simply terminate the process running the script:
CTRL + C
If running as a background process, use:
kill $(lsof -t -i:1080)
Replace 1080
with the actual port if different.
Alternatively, you can stop the server within the script:
proxyServer.server.close(() => {
console.log("Proxy server closed.");
});
process.on('uncaughtException', (err) => {
console.error("Unhandled exception:", err);
});
process.on('unhandledRejection', (reason, promise) => {
console.error("Unhandled rejection:", reason);
});
Finds an available port.
Validates the user configuration.
Validates the proxy settings.
Starts the SOCKS5 proxy server.
-
{ server: Object, port: number, user: null, password: null }
if successful. -
{ server: Object, port: number, user: string, password: string }
if successful. -
{ server: null, port: null, user: null, password: null }
if an error occurs.