Skip to content

Instantly share code, notes, and snippets.

@cupcakearmy
Created February 13, 2020 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cupcakearmy/7c30d5791280a27fadf04ffab1733ac7 to your computer and use it in GitHub Desktop.
Save cupcakearmy/7c30d5791280a27fadf04ffab1733ac7 to your computer and use it in GitHub Desktop.
Nord VPN random proxy
from json import loads
from urllib.request import urlopen
from random import choice
from time import sleep
from html import escape
from requests import get
with urlopen("https://api.nordvpn.com/server") as url:
data = loads(url.read().decode())
cleaned = [
{
'domain': item['domain'],
'country': item['flag'].lower(),
# 'features': item['features'],
}
for item in data
if item['features']['proxy_ssl'] and item['features']['proxy']
]
# de = [
# item
# for item in cleaned
# if item['country'] == 'de'
# ]
contries = set([
item['country']
for item in cleaned
])
def get_random_proxy() -> str:
selected = choice(cleaned)['domain']
server = f'username:password@{selected}:80'
return {
'http': f'http://{server}',
'https': f'https://{server}',
}
proxies = get_random_proxy()
print(proxies)
for _ in range(1):
ip = get('http://api.ipify.org', proxies=proxies).text
print('My public IP address is: {}'.format(ip))
sleep(.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment