How do I use nordvpn servers as python requests proxies

2024/10/14 1:13:33

Don't ask how, but I parsed the server endpoints of over 5000 nordvpn servers. They usually are something like ar15.nordvpn.com for example. I'm trying to use nordvpn servers as request proxies. I know its possible because nordvpn has a tutorial in setting it up the same way in browsers using port 80. Nordvpn only allows 6 simultaneous connections at the same time. My problem is that what im doing is for each server, i will send a request with that vpn proxy. After the request is sent it finishes. But for some reason even after the request finished the vpn connection somehow seams to be still connected because after the 6th request it fails. I know nordvpn only allows 6 connections at a time but this is one connection after another. The weirdest part is that they immediately go through again after i restart the script(until it reaches the 6th request). So its not nordvpn rate limiting but somehow requests are keeping an established connection.

What ive tried so far is asking r/learnpython. They were useless. The python discord got me far but never ultimately solved the problem. I have specified for the connection to close in the request header and even used request sessions, the with syntex for those sessions, and manually close the sesson even though with should take care of that. Disabling stream also doesnt do anything.


prox = [imagine a long list of nordvpn servers]def printip():# proxy auth according to request docsprox = {'https': 'https://[email protected]:password123@{}:80/'.format(i)}try:with requests.Session() as s:s.headers['Connection'] = 'close'r = s.get('https://api.myip.com', proxies=prox, stream=False)print(r.json()['ip'])s.close()except Exception as x:print('bruh')for i in prox:# i is the server endpointprintip()time.sleep(3)

I expected that the requests would work indefinitely but somehow the vpn connection still stays alive.

Answer

This question is over a year old, but I thought it could be worth an answer. Unofficially, according to nordvpn's support the HTTP/HTTPS servers are no longer maintained and they will be all discontinued soon.

As an alternative you can use socks5 proxies. Unlike HTTP proxies, which can only interpret and work with HTTP and HTTPS websites, SOCKS5 proxies can work with any traffic. Example with python requests:

First install requests[socks] or pysocks, then:

import requests
with requests.Session() as s:# s.keep_alive = Falses.headers['Connection'] = 'close'prox = {'https':'socks5://user:pass@host:port'}r = s.get('https://api.myip.com', proxies=prox)print(r.json()['ip'])s.close()

Nordvpn only have a limited number of Socks5 servers using Port 1080, these are:

amsterdam.nl.socks.nordhold.net
atlanta.us.socks.nordhold.net
dallas.us.socks.nordhold.net
dublin.ie.socks.nordhold.net
ie.socks.nordhold.net
los-angeles.us.socks.nordhold.net
nl.socks.nordhold.net
se.socks.nordhold.net
stockholm.se.socks.nordhold.net
us.socks.nordhold.net

You can ping each server to get the host IP address.


Optionally, you can make a TCP request using python. If you want to properly connect to nordvpn servers you could create an adapter that handles ciphers for your ssl connection. Some of these configurations need to specify the following: (read here)

TCP Port: 443
Tunnel Protocol: TCP (or UDP)
Encryption Cipher: AES-256-CBC
Hash Algorithm: SHA-512
User Pass Authentication: Enable
Username, Password: Your NordVPN service credentials

To make this work in python (to some extent not guaranteed though), read these SO questions:

https://en.xdnf.cn/q/69466.html

Related Q&A

Python Proxy Settings

I was using the wikipedia module in which you can get the information that is present about that topic on wikipedia. When I run the code it is unable to connect because of proxy. When I connected PC to…

Docker - Run Container from Inside Container

I have two applications:a Python console script that does a short(ish) task and exits a Flask "frontend" for starting the console app by passing it command line argumentsCurrently, the Flask …

Way to run Maven from Python script?

(I am using Windows.)I am trying to run maven from a python script. I have this:import subprocessmvn="C:\\_home\\apache-maven-2.2.1\\bin\\mvn.bat --version" p = subprocess.Popen(mvn, shell=Tr…

Why does testing `NaN == NaN` not work for dropping from a pandas dataFrame?

Please explain how NaNs are treated in pandas because the following logic seems "broken" to me, I tried various ways (shown below) to drop the empty values.My dataframe, which I load from a C…

Python dynamic import methods from file [duplicate]

This question already has answers here:How can I import a module dynamically given its name as string?(10 answers)How can I import a module dynamically given the full path?(37 answers)Closed last yea…

Python list does not shuffle in a loop

Im trying to create an randomized list of keys by iterating:import randomkeys = [1, 2, 3, 4, 5] random.shuffle(keys) print keysThis works perfect. However, if I put it in a loop and capture the output:…

Python extract max value from nested dictionary

I have a nested dictionary of the form:{2015-01-01: {time: 8, capacity: 5}, 2015-01-02: {time: 8, capacity: 7},2015-01-03: {time: 8, capacity: 8} etc}The dictionary is created from a csv file using dic…

Exponential Decay on Python Pandas DataFrame

Im trying to efficiently compute a running sum, with exponential decay, of each column of a Pandas DataFrame. The DataFrame contains a daily score for each country in the world. The DataFrame looks lik…

TensorFlow - why doesnt this sofmax regression learn anything?

I am aiming to do big things with TensorFlow, but Im trying to start small. I have small greyscale squares (with a little noise) and I want to classify them according to their colour (e.g. 3 categories…

Extended example to understand CUDA, Numba, Cupy, etc

Mostly all examples of Numba, CuPy and etc available online are simple array additions, showing the speedup from going to cpu singles core/thread to a gpu. And commands documentations mostly lack good …