0

I need to connect to a web page with node js server. There is a section in the site that accept some range of iP that they could have a request. Is it possible when I could load the page in Node ( e.g. puppeteer) when I need to click on some link on the page that needs specific IP, I spoof my IP?

Thanks

Sami
  • 5
  • 1
  • 4
  • Please [edit] your question to: clarify title of question, more details or clarify of problem, improve content quality, include [example] of your code, include error message, include the current result, include the expected result, list used tools. See [ask] – Gander Dec 23 '20 at 22:25

2 Answers2

2

No, this is not possible, assuming the web page's server is using your network-level IP information. While you could spoof your IP address, you could not get a response back from the server: the source IP you send to the server is how the server knows where to send a response to complete a TCP handshake.

It's as if you're trying to get into a club that only allows in residents with addresses on Main Street. You go up to the bouncer, and say, "Hey, I live on Main Street! My address is 123 Main Street." And the Bouncer says, "Okay, we'll slip a secret code under the door at 123 Main Street; come back here with that code and we'll talk." You've successfully lied about your address, but unless you can prove that's your address (i.e., you genuinely have access to get inside the house at 123 Main Street), you aren't going to get in the club.

If you need to spoof your IP, you need control of a machine that really does have that IP address. One possibility is a proxy machine, which forwards messages between you and the server you want to talk to. If the proxy has a whitelisted IP address, and it doesn't advertise your real original IP, then the server has no way of knowing the request originally came from a machine with a non-whitelisted IP. In the Main Street analogy, imagine that the real owners of 123 Main Street say, "Anyone may come inside our house at 123 Main Street and collect mail," then you can get the secret code that the club sent there. Even though you don't really live at 123 Main, the owners might allow you to pretend you do.

apsillers
  • 112,806
  • 17
  • 235
  • 239
  • Thanks but how is about using proxies then? – Sami Dec 23 '20 at 14:13
  • I also should mention I need to load a page ( it could be with my machine IP ) then when it is loaded as a HTML inside node then I want to click on a link in that page with another IP address basically – Sami Dec 23 '20 at 14:14
  • @Sami Sure, if the real owners of 123 Main Street say, "Anyone may come inside our house at 123 Main St. and collect mail," then you can get the secret code that the club sent there! In the case of a proxy, the operator of the proxy gives you some (very limited) control and access to their machine. – apsillers Dec 23 '20 at 14:15
  • thanks but do you have any link that I can increase my knowledge in this perspective? Another thing is that is is possible as a request inside node js I change my IP for puppeteer? so basically I send the click on the loaded HTML but somehow in the header I change the IP – Sami Dec 23 '20 at 14:23
  • @Sami You can change your IP address in the IP header, which would cause a new TCP handshake (since the server says, "ah, a new machine is trying to talk to me!") and then the server would try to talk to your fake IP address. When you say "My IP address is W.X.Y.Z," the server will try to start a connection with the machine at W.X.Y.Z. If you don't control that machine, you don't get to be part of that conversation. If you want to talk to the server, don't say your IP address is something it isn't. – apsillers Dec 23 '20 at 14:28
  • If you know of a proxy on the desired IP range that you are authorized to use, you can sent your request through the proxy: https://stackoverflow.com/questions/3862813/how-can-i-use-an-http-proxy-with-node-js-http-client If you don't know of a proxy on the desired IP range that will help you out, then this is a lie that the infrastructure of the internet will not allow you to tell `:)` – apsillers Dec 23 '20 at 14:29
  • @ apsillers Thanks I got your point so the only way is proxies but for example could I tell to proxy to click on specific location on a loaded page? – Sami Dec 23 '20 at 14:31
  • @Sami No, proxies transfer network requests. I assume when you click on the page in Puppeteer (on your real machine), it causes a network request. Make your network requests go through the proxy (per https://stackoverflow.com/questions/3862813/how-can-i-use-an-http-proxy-with-node-js-http-client, or possibly some Puppeteer-specific proxy setting, e.g. https://blog.scrapinghub.com/how-to-use-a-proxy-in-puppeteer). – apsillers Dec 23 '20 at 14:41
  • thanks. So basically there is not any way :( – Sami Dec 23 '20 at 15:07
  • @Sami The server doesn't see the click happening on your machine; the server only knows you clicked on the page because of a network request. So, if the request came from the proxy, it would look as if the click happened on the proxy. – apsillers Dec 23 '20 at 16:36
  • Thanks so with a proxy I could achieve it then. I will check it how could I use proxies in Node then – Sami Dec 23 '20 at 16:59
  • @ apsillers if I use request object and set the proxy from different proxy list, the end server could understand that i am in the back of proxy? So basically the proxies make some changes on the header that identifies they are not the real source origin without showing who is the source origin? – Sami Dec 23 '20 at 22:13
  • @Sami Yes, many proxies choose to set the [`X-Forwarded-For`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For) header in their proxied requests. There's no technical reason they *must* do that, but many choose to do so (and many services choose to check for it). – apsillers Dec 23 '20 at 22:19
  • @ apsillers really thanks man. Is there any terms for proxies that they do not use x-forwarded-For header that I could find such proxies? – Sami Dec 23 '20 at 22:24
0

If you just want to let your server knows your HTTP request IP address is changed, you can try to use X-Forwarded-For request header. Refer https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For

headers['X-Forwarded-For'] = '10.77.77.77'; // use another IP address

Hope your server can use that header.

pascal918
  • 369
  • 3
  • 5