0

I would like to know if it is possible for me to, in nodejs, connect to a proxy with the ip and port, execute some code with the proxies ip and not my local one, and then disconnect. An example (completely nonexistent just for helping explain better):

function codeToExecute() {
    logIP(); //non-existent function to log the current ip, should log the proxies ip and not mine
    //more code here to be executed under the proxie's ip
}

var connectProxy = require('someproxyscript');
connectProxy.setProxy('192.781.892.32','8080').execute(codeToExecute();)
connectProxy.disconnect();

This is not asking how to get html headers or anything like that, and I would not prefer to use NodeJS http lib, I want to be able to execute a section of my code under a different ip address then what mine is, then disconnect and go back to my own ip address. Basically, I want to proxy a line of code.

Mr.Sonic
  • 31
  • 1
  • 7
  • Possible duplicate of [How can I use an http proxy with node.js http.Client?](http://stackoverflow.com/questions/3862813/how-can-i-use-an-http-proxy-with-node-js-http-client) – krl Jan 01 '16 at 22:37
  • No, that's not what I want to do – Mr.Sonic Jan 01 '16 at 23:04
  • I wish to proxy a standard line of JavaScript code so it will run with a different ip address then my own, and I can repeat this multiple times with different proxies in the same script. – Mr.Sonic Jan 02 '16 at 01:16
  • I do not wish to proxy an http request, I wish to run standard JavaScript under a different ip address, that is what makes my question different then the linked question. – Mr.Sonic Jan 02 '16 at 01:18
  • Then you have to be more specific with what you want to do. If it's anything to do with `http` request, the previous answer is still good for your purpose. – krl Jan 02 '16 at 07:50
  • No, nothing to do with http requests I want to connect to a SOCKS 5 proxy and execute normal Javascript code, not make an http request. – Mr.Sonic Jan 02 '16 at 18:07
  • What will your JavaScript code that it requires proxy? It won't use `http` what then? – krl Jan 02 '16 at 21:04
  • It will execute a function in a nodejs Lib I have that will connect to a websocket server; this connection to the websocket server cannot be done with the http lib, there is a specific way it has to be executed, hence the executing normal Javascript part. – Mr.Sonic Jan 02 '16 at 23:01
  • What WebSockets library are you using? ws? – krl Jan 03 '16 at 22:32
  • Not a websocket library, just a library i made that is using ws to connect to a server and send all the stats and also has a receiver for code sent back to the client from the server. It is not just a single ws connection and that's it, it has a whole bunch of cases and a switch for what it recieves. That is why i need to be able to execute normal javascript under a proxy. – Mr.Sonic Jan 04 '16 at 02:41
  • There is no such thing as executing JavaScript code in Node.js behind a proxy. If you are not connecting to network, there is obviously no need for a proxy. If you are connecting to network, you usually use some libraries which may provide functionality to process requests via proxy. If you are not using any libraries, just your own code, it is your responsibility to manually implement functionality to connect to a proxy. Another option is to interface with an OS and use its tools to connect to a proxy. – krl Jan 04 '16 at 07:29

0 Answers0