Socket
Socket
Sign inDemoInstall

socks

Package Overview
Dependencies
0
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    socks

socks client, support socks version 5


Version published
Maintainers
1
Install size
4.34 kB
Created

Package description

What is socks?

The 'socks' npm package is a comprehensive Node.js library for working with SOCKS proxies. It supports SOCKS v4, v4a, and v5 protocols and can be used to create both SOCKS proxy clients and servers. It allows for proxying TCP and UDP connections, handling DNS lookups, and provides a way to work with different authentication methods.

What are socks's main functionalities?

Creating a SOCKS client

This code sample demonstrates how to create a SOCKS client that connects to a specified destination through a SOCKS proxy server.

const { SocksClient } = require('socks');

const options = {
  proxy: {
    host: 'host', // ipv4, ipv6, or hostname
    port: 1080,
    type: 5 // Proxy version (4, 5)
  },
  command: 'connect',
  destination: {
    host: 'destinationHost',
    port: 80
  }
};

SocksClient.createConnection(options, (err, info) => {
  if (err) {
    console.log(err);
    return;
  }
  const socket = info.socket;
  console.log('Connected to server through SOCKS proxy');
});

Creating a SOCKS server

This code sample shows how to create a SOCKS server that listens for incoming connections and can handle custom authentication.

const socks = require('socks').SocksServer;

const server = new socks({
  proxy: {
    ipaddress: 'localhost',
    port: 1080,
    type: 5
  },
  authenticate: function(username, password, socket, callback) {
    // Custom authentication logic
    callback();
  }
});

server.listen();

server.on('proxyConnect', (info, destinationSocket) => {
  console.log(`Accepted connection to ${info.host}:${info.port}`);
});

Handling UDP connections

This code sample illustrates how to handle UDP connections through a SOCKS proxy using the 'associate' command.

const { SocksClient } = require('socks');

const options = {
  proxy: {
    host: 'host',
    port: 1080,
    type: 5
  },
  command: 'associate',
  destination: {
    host: '0.0.0.0', // The local interface to bind for UDP association
    port: 0 // A random port will be used
  }
};

SocksClient.createConnection(options, (err, info) => {
  if (err) {
    console.log(err);
    return;
  }
  const udpSocket = info.socket;
  console.log('UDP association has been established.');
});

Other packages similar to socks

Readme

Source

socks client

Keywords

FAQs

Last updated on 15 Feb 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc