Skip to content

Commit

Permalink
find servers optimized for netflix #84
Browse files Browse the repository at this point in the history
  • Loading branch information
jotyGill committed Jan 14, 2018
1 parent 96d96b7 commit 470efb6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion openpyn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "2.1.4"
__version__ = "2.1.5"
__license__ = "GNU General Public License v3 or later (GPLv3+)"
25 changes: 22 additions & 3 deletions openpyn/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,34 @@ def filter_by_country(country_code, type_filtered_servers):
for aServer in type_filtered_servers:
if aServer["domain"][:2].lower() == country_code.lower():
remaining_servers.append(aServer)
# print(remaining_servers)
# print(aServer["domain"])
return remaining_servers


def filter_by_type(json_response, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos):
def filter_by_type(json_response, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix):
remaining_servers = []
serverCount = 0
netflix_srv = [[707, 710, "us"], [722, 733, "us"], [868, 875, "us"], [884, 887, "us"],
[940, 947, "us"], [952, 963, "us"], [980, 987, "us"], [1074, 1153, "us"],
[1154, 1195, "us"], [1196, 1287, "us"], [1289, 1292, "us"], [1297, 1312, "us"],
[1314, 1317, "us"], [1322, 1353, "us"], [1358, 1365, "us"], [1370, 1385, "us"],
[1394, 1421, "us"], [1422, 1457, "us"], [15, 20, "uk"], [30, 34, "uk"],
[36, 41, "uk"], [47, 51, "uk"], [53, 101, "uk"], [190, 192, "uk"],
[196, 207, "uk"], [228, 239, "uk"], [248, 251, "uk"], [256, 279, "uk"],
[300, 323, "uk"], [328, 331, "uk"], [348, 351, "uk"],
[30, 44, "fr"], [45, 63, "fr"], [65, 76, "fr"], [77, 80, "fr"],
[92, 95, "nl"], [165, 170, "ca"]]

for eachServer in json_response:
serverCount += 1
if netflix:
for server in netflix_srv:
for number in range(server[0], server[1] + 1):
# print(server[2]+str(number)+".")
# print(eachServer["domain"])
if server[2]+str(number)+"." in eachServer["domain"]:
remaining_servers.append(eachServer)
# print(eachServer["domain"])
for ServerType in eachServer["categories"]:
# print(eachServer["categories"])
if p2p and ServerType["name"] == "P2P":
Expand All @@ -43,7 +62,7 @@ def filter_by_type(json_response, p2p, dedicated, double_vpn, tor_over_vpn, anti
if anti_ddos and ServerType["name"] == "Anti DDoS":
remaining_servers.append(eachServer)
if p2p is False and dedicated is False and double_vpn is False and \
tor_over_vpn is False and anti_ddos is False:
tor_over_vpn is False and anti_ddos is False and netflix is False:
if ServerType["name"] == "Standard VPN servers":
remaining_servers.append(eachServer)
# print("Total available servers = ", serverCount)
Expand Down
48 changes: 30 additions & 18 deletions openpyn/openpyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def main():
parser.add_argument(
'--anti-ddos', dest='anti_ddos', help='Only look for servers with "Anti DDos" support',
action='store_true')
parser.add_argument(
'--netflix', dest='netflix', help='Only look for servers that are optimised for "Netflix"',
action='store_true')
parser.add_argument(
'--test', help='Simulation only, do not actually connect to the vpn server',
action='store_true')
Expand All @@ -116,15 +119,15 @@ def main():
args.daemon, args.max_load, args.top_servers, args.pings,
args.kill, args.kill_flush, args.update, args.list_servers,
args.force_fw_rules, args.p2p, args.dedicated, args.double_vpn,
args.tor_over_vpn, args.anti_ddos, args.test, args.internally_allowed,
args.tor_over_vpn, args.anti_ddos, args.netflix, args.test, args.internally_allowed,
args.skip_dns_patch, args.silent)


def run(
# run openpyn
init, server, country_code, country, area, tcp, daemon, max_load, top_servers,
pings, kill, kill_flush, update, list_servers, force_fw_rules,
p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos, test,
p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix, test,
internally_allowed, skip_dns_patch, silent):
port = "udp"
if tcp:
Expand Down Expand Up @@ -188,6 +191,8 @@ def run(
openpyn_options += " --tor "
if anti_ddos:
openpyn_options += " --anti-ddos "
if netflix:
openpyn_options += " --netflix "
if test:
openpyn_options += " --test "
if internally_allowed:
Expand Down Expand Up @@ -221,11 +226,12 @@ def run(
# a hack to list all countries and thier codes when no arg supplied with "-l"
elif list_servers != 'nope': # means "-l" supplied
if list_servers is None: # no arg given with "-l"
if p2p or dedicated or double_vpn or tor_over_vpn or anti_ddos:
if p2p or dedicated or double_vpn or tor_over_vpn or anti_ddos or netflix:
# show the special servers in all countries
display_servers(
list_servers="all", area=area, p2p=p2p, dedicated=dedicated,
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos)
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos,
netflix=netflix)
else:
list_all_countries()
# if a country code is supplied give details about that country only.
Expand All @@ -235,7 +241,8 @@ def run(
list_servers = get_country_code(full_name=list_servers)
display_servers(
list_servers=list_servers, area=area, p2p=p2p, dedicated=dedicated,
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos)
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos,
netflix=netflix)

# only clear/touch FW Rules if "-f" used
elif force_fw_rules:
Expand All @@ -260,7 +267,7 @@ def run(
country_code = country_code.lower()
better_servers_list = find_better_servers(
country_code, area, max_load, top_servers, tcp, p2p,
dedicated, double_vpn, tor_over_vpn, anti_ddos)
dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix)
pinged_servers_list = ping_servers(better_servers_list, pings)
chosen_servers = choose_best_servers(pinged_servers_list)

Expand Down Expand Up @@ -326,13 +333,13 @@ def get_json(url):

# Gets json data, from api.nordvpn.com. filter servers by type, country, area.
def get_data_from_api(
country_code, area, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos):
country_code, area, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix):

url = "https://api.nordvpn.com/server"
json_response = get_json(url)

type_filtered_servers = filters.filter_by_type(
json_response, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos)
json_response, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix)
if country_code != "all": # if "-l" had country code with it. e.g "-l au"
type_country_filtered = filters.filter_by_country(country_code, type_filtered_servers)
if area is None:
Expand All @@ -346,7 +353,7 @@ def get_data_from_api(
# Filters servers based on the speficied criteria.
def find_better_servers(
country_code, area, max_load, top_servers, tcp, p2p, dedicated,
double_vpn, tor_over_vpn, anti_ddos):
double_vpn, tor_over_vpn, anti_ddos, netflix):
if tcp:
used_protocol = "OPENVPN-TCP"
else:
Expand All @@ -355,7 +362,8 @@ def find_better_servers(
# use api.nordvpn.com
json_res_list = get_data_from_api(
country_code=country_code, area=area, p2p=p2p, dedicated=dedicated,
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos)
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos,
netflix=netflix)

server_list = filters.filter_by_protocol(json_res_list=json_res_list, tcp=tcp)

Expand All @@ -368,19 +376,21 @@ def find_better_servers(
print("in Location" + Fore.GREEN, json_res_list[0]["location_names"], end=" ")

print(Fore.BLUE + "With 'Load' less than", Fore.GREEN + str(max_load) + Fore.BLUE,
"Which Support", Fore.GREEN + used_protocol + Fore.BLUE, end=" ")
"Which Support", Fore.GREEN + used_protocol, end=" ")
if p2p:
print(", p2p = ", p2p, end=" ")
if dedicated:
print(", dedicated =", dedicated, end=" ")
if double_vpn:
print(", double_vpn =", double_vpn, end=" ")
if tor_over_vpn:
print(",tor_over_vpn =", tor_over_vpn, end=" ")
print(", tor_over_vpn =", tor_over_vpn, end=" ")
if anti_ddos:
print(",anti_ddos =", anti_ddos, end=" ")
print(", anti_ddos =", anti_ddos, end=" ")
if netflix:
print(", netflix =", netflix, end=" ")

print("are :" + Fore.GREEN, better_servers_list, Fore.BLUE + "\n")
print(Fore.BLUE + "are :" + Fore.GREEN, better_servers_list, Fore.BLUE + "\n")
return better_servers_list


Expand Down Expand Up @@ -468,7 +478,7 @@ def update_config_files():
root.verify_root_access("Root access needed to write files in '/usr/share/openpyn/files'")
try:
subprocess.check_call(
"sudo wget -N https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip \
"sudo wget https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip \
-P /usr/share/openpyn/".split())
subprocess.check_call(
"sudo unzip -u -o /usr/share/openpyn/ovpn -d /usr/share/openpyn/files/".split())
Expand All @@ -478,13 +488,15 @@ def update_config_files():


# Lists information abouts servers under the given criteria.
def display_servers(list_servers, area, p2p, dedicated, double_vpn, tor_over_vpn, anti_ddos):
def display_servers(list_servers, area, p2p, dedicated, double_vpn,
tor_over_vpn, anti_ddos, netflix):
servers_on_web = set() # servers shown on the website

# if list_servers was not a specific country it would be "all"
json_res_list = get_data_from_api(
country_code=list_servers, area=area, p2p=p2p, dedicated=dedicated,
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos)
double_vpn=double_vpn, tor_over_vpn=tor_over_vpn, anti_ddos=anti_ddos,
netflix=netflix)
# print(json_res_list)

if area:
Expand All @@ -505,7 +517,7 @@ def display_servers(list_servers, area, p2p, dedicated, double_vpn, tor_over_vpn
print(location[2])

if list_servers != "all" and p2p is False and dedicated is False and double_vpn is False \
and tor_over_vpn is False and anti_ddos is False and area is False:
and tor_over_vpn is False and anti_ddos is False and netflix is False and area is False:
# else not applicable.
print_latest_servers(server_set=servers_on_web)
sys.exit()
Expand Down

0 comments on commit 470efb6

Please sign in to comment.