associate.js 854 B

123456789101112131415161718192021222324252627282930313233
  1. var Socks = require('../index.js');
  2. var dgram = require('dgram');
  3. var options = {
  4. proxy: {
  5. ipaddress: "202.101.228.108",
  6. port: 1080,
  7. type: 5,
  8. command: 'associate'
  9. },
  10. target: {
  11. host: "0.0.0.0",
  12. port: 0
  13. }
  14. };
  15. Socks.createConnection(options, function(err, socket, info) {
  16. if (err)
  17. console.log(err);
  18. else {
  19. console.log("Connected");
  20. // Associate request completed.
  21. // Now we can send properly formed UDP packet frames to this endpoint for forwarding:
  22. console.log(info);
  23. // { port: 4381, host: '202.101.228.108' }
  24. var udp = new dgram.Socket('udp4');
  25. var packet = SocksClient.createUDPFrame({ host: "1.2.3.4", port: 5454}, new Buffer("Hello"));
  26. udp.send(packet, 0, packet.length, info.port, info.host);
  27. }
  28. });