6

Is there a way to send UDP packets through a SOCKS5 proxy in NodeJS?

Similarly, is it possible to bind a UDP socket to a specific localAddress?

4

3 回答 3

1

SOCKS5 协议支持 UDP 连接,但是大多数 SOCKS5 库仅支持 TCP,因为 UDP 在 Web 上不经常使用(DNS 除外)。协议本身并不是很复杂,因此重写现有库(也许是这个?)以满足您的需求应该不难。

于 2013-05-14T22:46:56.600 回答
1

要从您的客户端发送 UDP 数据包,您必须在客户端连接请求的字段 2 中指定值 0x03。查看客户端连接请求的字段

field 1: SOCKS version number, 1 byte (must be 0x05 for this version)

field 2: command code, 1 byte:

0x01 = establish a TCP/IP stream connection

0x02 = establish a TCP/IP port binding

0x03 = associate a UDP port

field 3: reserved, must be 0x00

field 4: address type, 1 byte:

0x01 = IPv4 address

0x03 = Domain name

0x04 = IPv6 address

field 5: destination address of

4 bytes for IPv4 address

1 byte of name length followed by the name for Domain name

16 bytes for IPv6 address

field 6: port number in a network byte order, 2 bytes

例如,引用库中的代码行需要从 0x01 更改为 0x03:

buffer.push(0x01); // Command code: establish a TCP/IP stream connection

我不知道您如何绑定到特定的本地地址。

于 2013-05-20T00:36:28.560 回答
0

根据http://www.ietf.org/rfc/rfc1928.txthttp://en.wikipedia.org/wiki/SOCKS#SOCKS5,Socks5 应该真正支持 UDP。

但是,如果您查看一些 SOCKS5 实现,您会发现实现中不支持 UDP。例如:https ://gist.github.com/telamon/1127459或https://gist.github.com/robertpitt/3203203 (.

因此,简短的回答是否定的,除非您找到支持它的库(UDP 绑定)。

于 2013-05-19T11:11:42.153 回答