Home > Blockchain >  How to do a curl call from 2 specific locations in the world in Ruby?
How to do a curl call from 2 specific locations in the world in Ruby?

Time:01-29

I'm doing this in Ruby:

response = `curl -w \"%{response_code}\:%{time_total}\" https://google.com -o /dev/null -s`
response_code, time_total = response.split(':')

It's kind of a ping. This works perfectly and gives me an HTTP response code and total response time.

Now, I would like to do this call from 2 specific locations in the world (let's say from the US and from Germany).

How can I do that? Should I buy a static IP and then instruct curl to do the call from that IP somehow?

Any idea?

CodePudding user response:

A machine is physically located somewhere. If you want to do a ping from another location, you would probably need to buy a VPS server in this another location and run the same code from there.

CodePudding user response:

You should probably use a proxy for this. There are a lot of options out there. I like webshare and they have a free tier. However, you may have to pay if you want a specific location.

Then you would need to configure curl to use the proxy.

There should be examples in the docs for your proxy provider, but here's a snippet from the curl help page:

 -x, --proxy [protocol://]host[:port] Use this proxy
  •  Tags:  
  • Related