Directory
Directory

Reputation: 143

How do I use nordvpn servers as python requests proxies

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 docs
    prox = {
        '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 endpoint
    printip()
    time.sleep(3)

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

Upvotes: 7

Views: 20201

Answers (1)

Ava Barbilla
Ava Barbilla

Reputation: 1053

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 = False
    s.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:

Upvotes: 14

Related Questions