Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL through OpenVPN or PPTP

Tags:

php

curl

Is there a way to execute cURL requests through a VPN such as OpenVPN or PPTP?

I'm aware that i can use a proxy, But a VPN is different.

like image 460
CodeOverload Avatar asked Apr 08 '12 12:04

CodeOverload


2 Answers

EDIT: JULY 2013

I was getting a few emails on this so I wrapped it all up into a blogpost: http://www.georgiecasey.com/2013/07/26/how-to-use-overplay-and-other-vpns-as-a-curl-proxy/


Yes, but first you've to setup the VPN on a separate interface so your whole server doesn't use the VPN. I'm no OpenVPN expert but I did this with the dev switch to specify the TUN/TAP virtual network device: dev proxy1. More info on the OpenVPN man page.

Then use this line of PHP code in your scripts.

curl_setopt($ch, CURLOPT_INTERFACE, "proxy1");

I did this so I could use all the IPs of overplay.net to scrape stuff on my server. These IPs change often so I had a cronjob that pulled the zip file of IPs, created an OpenVPN config file for each IP, started each VPN and put all IPs and interface names in a DB table. Then my scripts just pulled random interface names from the DB and used that in the curl. Worked a treat.

like image 80
georgiecasey Avatar answered Sep 23 '22 17:09

georgiecasey


cURL simply uses the operating system's network stack, and does not implement TCP (or lower-level protocols) itself.

Therefore, it works fine with when the operating system is configured to route network communication through a virtual adapter, no matter how that adapter is implemented.

like image 40
phihag Avatar answered Sep 21 '22 17:09

phihag