Skip to content

Instantly share code, notes, and snippets.

@adentify
Last active January 16, 2022 19:57
Show Gist options
  • Save adentify/33a4238699026616e0566622791601cb to your computer and use it in GitHub Desktop.
Save adentify/33a4238699026616e0566622791601cb to your computer and use it in GitHub Desktop.
How to get PHP & CURL to work with NordVPN Socks5 Proxy Servers
<?php
header('Content-Type:text/plain'); // this script dumps the response object to the page, this just ensures it looks nice in the browser
$conf["url"] = "https://ipapi.co/json/"; // the URL you wish to fetch, this particular endpoint will return a JSON object detailing Geo/IP details of the proxy you are using as a proof the proxy is working
$conf["useragent"] = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
// NordVPN socks servers use specifc domains it seems - https://support.nordvpn.com/Connectivity/Proxy/1047410732/Proxy-setup-on-uTorrent.htm
// uncomment whichever server you wish to check.
// $conf["proxy"]["host"] = "amsterdam.nl.socks.nordhold.net";
// $conf["proxy"]["host"] = "atlanta.us.socks.nordhold.net";
// $conf["proxy"]["host"] = "dallas.us.socks.nordhold.net";
// $conf["proxy"]["host"] = "dublin.ie.socks.nordhold.net";
$conf["proxy"]["host"] = "ie.socks.nordhold.net";
// $conf["proxy"]["host"] = "los-angeles.us.socks.nordhold.net";
// $conf["proxy"]["host"] = "nl.socks.nordhold.net";
// $conf["proxy"]["host"] = "se.socks.nordhold.net";
// $conf["proxy"]["host"] = "stockholm.se.socks.nordhold.net";
// $conf["proxy"]["host"] = "us.socks.nordhold.net";
// NordVPN uses 1080 for it's socks proxies
$conf["proxy"]["port"] = 1080;
// your normal user/pass credentials will not work, you have to use the 'service credentials' which can be obtained from your account dashboard athttps://my.nordaccount.com/dashboard/nordvpn/
$conf["proxy"]["user"] = "YOUR_SERVICE_USERNAME_HERE";
$conf["proxy"]["pass"] = "YOUR_SERVICE_PASSWORD_HERE";
// Instantiate the CURL instance
$curl = curl_init();
// define CURL parameters
curl_setopt($curl, CURLOPT_PROXY, $conf["proxy"]["host"]);
curl_setopt($curl, CURLOPT_PROXYPORT, $conf["proxy"]["port"]);
curl_setopt($curl, CURLOPT_PROXYUSERPWD, $conf["proxy"]["user"].":".$conf["proxy"]["pass"]);
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_URL, $conf["url"]);
curl_setopt($curl, CURLOPT_USERAGENT, $conf["useragent"]);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// fetch the page content/body
$html = curl_exec($curl);
// get connection data
$response = curl_getinfo($curl);
// add the proxy used to the response object
$response['proxy'] = $conf["proxy"]["host"];
// add the HTML body to the responseobject, comment out if not needed
$response['html'] = $html;
// close the curl instance
curl_close($curl);
// output the results
print_r($response);
?>
@adentify
Copy link
Author

I updated the example url that is requested to: https://ipapi.co/json/
This url returrns a JSON object with geo/ip data about the proxy server eg; country/location etc... handy to verify the proxy is working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment