How do I use nordvpn servers as python requests proxies
Asked Answered
B

1

7

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.

Barahona answered 8/7, 2019 at 11:32 Comment(10)
How does your header look like? You could try with requests.Session(config={'keep_alive': False}) as s: maybe?Spider
config doesn't exist as an argument and i already said im forcing the connection header to be close instead of keep aliveBarahona
my bad.. Did you manage to make it work? what about skipping the session, and only use request.get 2.python-requests.org//en/latest/user/advanced/#proxiesSpider
still havnt gotten it to work and i used everything.Barahona
I'm not sure if @Chris's answer is actually an answer to your question, but I added a comment on his answer. I tried https and couldn't get it to work until switching to tcp or udp. I tried 8 simultaneous requests in JavaScript and they all went through.Crinoid
So I ran into your issue - I see now that the issue is multiple connections to different servers. I opened up a new question for node.js: #58405466Crinoid
@Barahona how did you solve the problem?Grafting
@Grafting i didntBarahona
@Barahona are you sure the list of your servers (prox variable) are actually proxy enabled servers? not all of the nordvpn servers are proxy enabled, see nordvpn.com/servers/toolsGrafting
If you managed to somehow get the list of only proxy enabled servers of nordvpn please let me know how, in their website when you check the HTTP proxy option, it only shows the top one. and data dumps in pastebin list all their servers and not just only http proxy enabled serversGrafting
B
14

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:

Bracing answered 24/12, 2020 at 17:58 Comment(4)
Thank you for your reply. This answer actually helps me to solve something i'm handling with nordvpn. Right now I have a service that requests an API, but once in a while I have to change the proxy, since I use nordvpn what I do is to run a batch script to change the vpn (nordvpn has an Ubuntu app that works well for this). But this solution kinda sucks. Regarding your solution, how fast is it do perform the authentication of the vpn under each request? Speed is important for me.Wretched
Hey man! Could you figure out how long the authentication process takes per request?Unconnected
Nord's socks5 list is way bigger now just hit curl -s https://nordvpn.com/api/server | jq -r ".[] | select(.features.socks==true) | [.domain, .name] | @tsv"Dumbarton
Hey you just saved me! I was going crazy because I use NordVPN and I couldn't find a single solution on SO that would work for me. With your example code I could make it work!Quarrier

© 2022 - 2024 — McMap. All rights reserved.