-1

I'm using a node module to create http proxy servers (node-socks)like this:

const { http } = require('@sansamour/node-socks')




http.createServer({
    authorization: function(u,p){
        return u == 'KeemROH' && p == 'Test'
    },
    port: 5000
});

http.createServer({
    authorization: function(u,p){
        return u == 'KeemROH' && p == 'Test'
    },
    port: 5001
});

http.createServer({
    authorization: function(u,p){
        return u == 'KeemROH' && p == 'Test'
    },
    port: 5002
});

http.createServer({
    authorization: function(u,p){
        return u == 'KeemROH' && p == 'Test'
    },
    port: 5003
});

http.createServer({
    authorization: function(u,p){
        return u == 'KeemROH' && p == 'Test'
    },
    port: 5004
});

Would it maybe be possible to make a loop that would maybe run:

http.createServer({
    authorization: function(u,p){
        return u == 'KeemROH' && p == 'Test'
    },
    port: 5000 // add +1 each loop so 5000, 5001, 5002, 5003, 5004 ect.
});

And have it loop a set number of times? So instead of rewriting it a number of times this can be the solution

KeemROH
  • 27
  • 6

1 Answers1

2

Is this what you are looking for:

const { http } = require('@sansamour/node-socks')

const numServers = 5;
const startingPort = 5000;

for (let i = 0; i < numServers; i++) {
    http.createServer({
        authorization: function(u,p){
            return u == 'KeemROH' && p == 'Test'
        },
        port: startingPort + i
    });
}
Shell Code
  • 682
  • 4
  • 9