From 9029178bf49ed8a7ab81550370c15b30147021ae Mon Sep 17 00:00:00 2001 From: Agent Buzz Date: Fri, 1 Nov 2024 21:50:39 -0500 Subject: [PATCH 1/5] Update api.py --- openpyn/api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openpyn/api.py b/openpyn/api.py index cacb5a5..894949e 100644 --- a/openpyn/api.py +++ b/openpyn/api.py @@ -70,7 +70,7 @@ def get_data_from_api( country_code: str, area: str, p2p: bool, dedicated: bool, double_vpn: bool, tor_over_vpn: bool, anti_ddos: bool, netflix: bool, location: float) -> List: country_code = country_code.lower() - url = "https://api.nordvpn.com/server" + url = "https://api.nordvpn.com/v1/servers?limit=0" json_response = get_json_cached(url) type_filtered_servers = [] @@ -92,7 +92,7 @@ def get_data_from_api( def list_all_countries() -> None: countries_mapping = {} - url = "https://api.nordvpn.com/server" + url = "https://api.nordvpn.com/v1/servers?limit=0" json_response = get_json_cached(url) for res in json_response: if res["domain"][:2] not in countries_mapping: @@ -103,7 +103,7 @@ def list_all_countries() -> None: def get_country_code(full_name: str) -> str: full_name = full_name.lower() - url = "https://api.nordvpn.com/server" + url = "https://api.nordvpn.com/v1/servers?limit=0" json_response = get_json_cached(url) for res in json_response: if res["country"].lower() == full_name: @@ -114,7 +114,7 @@ def get_country_code(full_name: str) -> str: def get_country_name(iso_code: str) -> str: iso_code = iso_code.lower() - url = "https://api.nordvpn.com/server" + url = "https://api.nordvpn.com/v1/servers?limit=0" json_response = get_json_cached(url) for res in json_response: if res["domain"][:2] == iso_code: From 2ca5e3bc07c5bdc25c47e014b1a0fb103e1a47e5 Mon Sep 17 00:00:00 2001 From: Agent Buzz Date: Fri, 1 Nov 2024 22:05:53 -0500 Subject: [PATCH 2/5] Update filters.py --- openpyn/filters.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/openpyn/filters.py b/openpyn/filters.py index 88c1339..797c787 100644 --- a/openpyn/filters.py +++ b/openpyn/filters.py @@ -130,25 +130,26 @@ def filter_by_type(json_response, p2p: bool, dedicated: bool, double_vpn: bool, for eachServer in json_response: server_count += 1 - for ServerType in eachServer["categories"]: - if p2p and ServerType["name"] == "P2P": - remaining_servers.append(eachServer) - break - if dedicated and ServerType["name"] == "Dedicated IP": - remaining_servers.append(eachServer) - break - if double_vpn and ServerType["name"] == "Double VPN": - remaining_servers.append(eachServer) - break - if tor_over_vpn and ServerType["name"] == "Onion Over VPN": - remaining_servers.append(eachServer) - break - if anti_ddos and ServerType["name"] == "Obfuscated Servers": - remaining_servers.append(eachServer) - break - if standard_vpn and ServerType["name"] == "Standard VPN servers": - remaining_servers.append(eachServer) - break + if "groups" in eachServer: + for ServerType in eachServer["groups"]: + if p2p and ServerType["title"] == "P2P": + remaining_servers.append(eachServer) + break + if dedicated and ServerType["title"] == "Dedicated IP": + remaining_servers.append(eachServer) + break + if double_vpn and ServerType["title"] == "Double VPN": + remaining_servers.append(eachServer) + break + if tor_over_vpn and ServerType["title"] == "Onion Over VPN": + remaining_servers.append(eachServer) + break + if anti_ddos and ServerType["title"] == "Obfuscated Servers": + remaining_servers.append(eachServer) + break + if standard_vpn and ServerType["title"] == "Standard VPN servers": + remaining_servers.append(eachServer) + break # logger.debug("Total available servers = ", serverCount) return remaining_servers From 8423074f2c952e007a7ae00918e3a7fafcfda5eb Mon Sep 17 00:00:00 2001 From: Agent Buzz Date: Fri, 1 Nov 2024 22:18:49 -0500 Subject: [PATCH 3/5] Update filters.py --- openpyn/filters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpyn/filters.py b/openpyn/filters.py index 797c787..1b692b0 100644 --- a/openpyn/filters.py +++ b/openpyn/filters.py @@ -28,9 +28,9 @@ def filter_by_area(area: str, type_country_filtered: List) -> List: def filter_by_country(country_code: str, type_filtered_servers: List) -> List: remaining_servers = [] for aServer in type_filtered_servers: - if aServer["domain"][:2] == country_code: + if aServer["hostname"][:2].lower() == country_code: remaining_servers.append(aServer) - # logger.debug(aServer["domain"]) + # logger.debug(aServer["hostname"]) return remaining_servers From aafa8b14ea1bc3ec0a215ec9dfc50da0ac47de52 Mon Sep 17 00:00:00 2001 From: Agent Buzz Date: Fri, 1 Nov 2024 22:22:12 -0500 Subject: [PATCH 4/5] Summary changing outdated json refs --- openpyn/api.py | 8 ++++---- openpyn/filters.py | 8 ++++---- openpyn/openpyn.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/openpyn/api.py b/openpyn/api.py index 894949e..2102444 100644 --- a/openpyn/api.py +++ b/openpyn/api.py @@ -95,8 +95,8 @@ def list_all_countries() -> None: url = "https://api.nordvpn.com/v1/servers?limit=0" json_response = get_json_cached(url) for res in json_response: - if res["domain"][:2] not in countries_mapping: - countries_mapping.update({res["domain"][:2]: res["country"]}) + if res["hostname"][:2] not in countries_mapping: + countries_mapping.update({res["hostname"][:2]: res["country"]}) for key, val in countries_mapping.items(): print("Full Name : " + val + "\t\tCountry Code : " + key) @@ -107,7 +107,7 @@ def get_country_code(full_name: str) -> str: json_response = get_json_cached(url) for res in json_response: if res["country"].lower() == full_name: - code = res["domain"][:2] + code = res["hostname"][:2] return code raise RuntimeError("Country Name Not Correct") @@ -117,7 +117,7 @@ def get_country_name(iso_code: str) -> str: url = "https://api.nordvpn.com/v1/servers?limit=0" json_response = get_json_cached(url) for res in json_response: - if res["domain"][:2] == iso_code: + if res["hostname"][:2] == iso_code: name = res["country"] return name raise RuntimeError("Country Code Not Correct") diff --git a/openpyn/filters.py b/openpyn/filters.py index 1b692b0..d4857fa 100644 --- a/openpyn/filters.py +++ b/openpyn/filters.py @@ -113,9 +113,9 @@ def filter_by_netflix(json_response, country_code: str) -> List: server_count += 1 for server in netflix_srv: for number in range(server[0], server[1] + 1): - if server[2] + str(number) + "." in eachServer["domain"]: + if server[2] + str(number) + "." in eachServer["hostname"]: remaining_servers.append(eachServer) - # logger.debug(eachServer["domain"]) + # logger.debug(eachServer["hostname"]) # logger.debug("Total available servers = ", serverCount) return remaining_servers @@ -160,10 +160,10 @@ def filter_by_protocol(json_res_list: List, tcp: bool) -> List: for res in json_res_list: # when connecting using TCP only append if it supports OpenVPN-TCP if tcp is True and res["features"]["openvpn_tcp"] is True: - remaining_servers.append([res["domain"][:res["domain"].find(".")], res["load"]]) + remaining_servers.append([res["hostname"][:res["hostname"].find(".")], res["load"]]) # when connecting using UDP only append if it supports OpenVPN-UDP elif tcp is False and res["features"]["openvpn_udp"] is True: - remaining_servers.append([res["domain"][:res["domain"].find(".")], res["load"]]) + remaining_servers.append([res["hostname"][:res["hostname"].find(".")], res["load"]]) return remaining_servers diff --git a/openpyn/openpyn.py b/openpyn/openpyn.py index 40dee23..3f99cca 100644 --- a/openpyn/openpyn.py +++ b/openpyn/openpyn.py @@ -1101,7 +1101,7 @@ def display_servers(list_servers: str, port: str, area: str, p2p: bool, dedicate # add server names to "servers_on_web" set for res in json_res_list: print("Server =", res["domain"][:res["domain"].find(".")], ", Load =", res["load"], - ", Country =", res["country"], ", Features", res["categories"], "\n") + ", Country =", res["country"], ", Features", res["groups"], "\n") servers_on_web.add(res["domain"][:res["domain"].find(".")]) if not area: From 3fe30b81e13f18ce6facbc21fff2ee0962b56950 Mon Sep 17 00:00:00 2001 From: Agent Buzz Date: Fri, 1 Nov 2024 22:25:11 -0500 Subject: [PATCH 5/5] Update filters.py --- openpyn/filters.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/openpyn/filters.py b/openpyn/filters.py index d4857fa..cef7307 100644 --- a/openpyn/filters.py +++ b/openpyn/filters.py @@ -158,12 +158,14 @@ def filter_by_protocol(json_res_list: List, tcp: bool) -> List: remaining_servers = [] for res in json_res_list: - # when connecting using TCP only append if it supports OpenVPN-TCP - if tcp is True and res["features"]["openvpn_tcp"] is True: - remaining_servers.append([res["hostname"][:res["hostname"].find(".")], res["load"]]) - # when connecting using UDP only append if it supports OpenVPN-UDP - elif tcp is False and res["features"]["openvpn_udp"] is True: - remaining_servers.append([res["hostname"][:res["hostname"].find(".")], res["load"]]) + if "technologies" in res: + for tech in res["technologies"]: + # when connecting using TCP only append if it supports OpenVPN-TCP + if tcp and tech["identifier"] == "openvpn_tcp": + remaining_servers.append([res["hostname"][:res["hostname"].find(".")], res["load"]]) + # when connecting using UDP only append if it supports OpenVPN-UDP + elif not tcp and tech["identifier"] == "openvpn_udp": + remaining_servers.append([res["hostname"][:res["hostname"].find(".")], res["load"]]) return remaining_servers