Last active
January 16, 2022 19:57
-
-
Save adentify/33a4238699026616e0566622791601cb to your computer and use it in GitHub Desktop.
How to get PHP & CURL to work with NordVPN Socks5 Proxy Servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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