Skip to content

Instantly share code, notes, and snippets.

@mzpqnxow
Last active March 9, 2023 21:28
Show Gist options
  • Save mzpqnxow/4b4d04e78227622992b4ab40e55291ce to your computer and use it in GitHub Desktop.
Save mzpqnxow/4b4d04e78227622992b4ab40e55291ce to your computer and use it in GitHub Desktop.
Get a list of all VyprVPN server IP addresses, hostnames and countries or a subset based on specified country/countries
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Retrieve list of all VyprVPN servers, relying on their publicly posted list which
is referenced on their site as an "official" source .. it seems this could change
but it hasn't in a long time
Dependency on BeautifulSoup
(Optional) dependency on the `progress` project @ https://pypi.org/project/progress/
$ pip install progress BeautifulSoup
If you leave out `progress` you won't get a nice progress meter with an ETA :<
"""
from __future__ import print_function
from __future__ import unicode_literals
from collections import defaultdict
from json import dumps
from socket import gethostbyname
from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup
try:
from progress.bar import Bar
HAS_PROGRESS = True
class InfoBar(Bar):
suffix = '%(percent).1f%% - %(eta)ds %(hostname)s'
_hostname = ''
def current(self, hostname):
self._hostname = hostname
@property
def hostname(self):
return self._hostname
@property
def remaining_hours(self):
return self.eta // 3600
except ImportError:
HAS_PROGRESS = False
def pretty(obj):
print(dumps(obj, indent=2))
def get_vyprvpn_servers(country=None, quiet=False, progress=True):
"""Return list or dict of VyprVPN servers, including IP address and hostname
If country is specified, it can be either a list/set or a string, to
select only servers from specific countries. A dictionary will be returned
with the keys being the country names and the values as a list of tuples
of (country, host, ip)
If country is None, return a simple list of tuples of (country, host, ip)
"""
def _progress(bar, current, finish=False):
if HAS_PROGRESS and not quiet:
bar.current(current)
if not finish:
bar.next()
else:
bar.finish()
country_to_server = defaultdict(list)
server_list = list()
contenturl = 'https://support.goldenfrog.com/hc/en-us/articles/360011055671-What-are-the-VyprVPN-server-addresses-'
soup = BeautifulSoup(urlopen(contenturl).read())
table = soup.find('table', attrs={'class': 'gf-table bordered vpn-server-list'})
rows = table.findAll('tr')
bar = None
if not quiet and HAS_PROGRESS:
bar = InfoBar('Processing', max=len(rows))
for row in rows:
location, hostname, _ = [data.find(text=True) for data in row.findAll('td')]
# if quiet is False:
# print('{} - {}'.format(location, hostname))
vpn_country = location.split('-')[0].strip()
if isinstance(country, basestring):
if vpn_country.lower() != country.lower():
_progress(bar, hostname)
continue
elif isinstance(country, (list, tuple, set)):
if vpn_country.lower() not in [chosen.lower() for chosen in country]:
_progress(bar, hostname)
continue
country_to_server[vpn_country].append([vpn_country, hostname, gethostbyname(hostname)])
server_list.append([vpn_country, hostname, gethostbyname(hostname)])
_progress(bar, hostname)
_progress(bar, '', finish=True)
if country is None:
return server_list
return country_to_server
def example_by_country(chosen_country):
# Get all servers in US, Mexico and Canada as a dictionary where the key
# is the country name and the value is a list of triplets (country, hostname, current ip)
# Basic example of how to access various fields easily for each
servers = get_vyprvpn_servers(country=chosen_country, quiet=True)
hostnames = [server[1] for server in [server_lists[0] for country, server_lists in servers.iteritems()]]
pretty(hostnames)
print('--- End Hostname List by Country ---')
ip_addresses = [server[2] for server in [server_lists[0] for country, server_lists in servers.iteritems()]]
pretty(ip_addresses)
print('--- End IP Address List by Country')
def example_all_servers():
# Get all servers as a list of triplets (country, hostname, current ip)
# Basic example of how to access the fields easily
servers = get_vyprvpn_servers()
hostnames = [record[1] for record in servers]
pretty(servers)
print('--- End Complete Server Record List ---')
pretty(hostnames)
print('--- End Complete Server Hostname List ---')
def main():
example_all_servers()
example_by_country(('US', 'Mexico', 'Canada'))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment