diff --git a/openpyn/api.py b/openpyn/api.py index cacb5a5..2102444 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,32 +92,32 @@ 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: - 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) 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: - code = res["domain"][:2] + code = res["hostname"][:2] return code raise RuntimeError("Country Name Not Correct") 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: + 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 88c1339..cef7307 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 @@ -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 @@ -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 @@ -157,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["domain"][:res["domain"].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"]]) + 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 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: