Beispiel #1
0
def find_better_servers(country_code: str, area: str, max_load: int,
                        top_servers: int, tcp: bool, p2p: bool,
                        dedicated: bool, double_vpn: bool, tor_over_vpn: bool,
                        anti_ddos: bool, netflix: bool, location: float,
                        stats: bool) -> List:
    if tcp:
        used_protocol = "OPENVPN-TCP"
    else:
        used_protocol = "OPENVPN-UDP"

    # use api.nordvpn.com
    json_res_list = api.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,
                                          netflix=netflix,
                                          location=location)

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

    better_servers_list = filters.filter_by_load(server_list, max_load,
                                                 top_servers)

    if stats:
        print(Style.BRIGHT + Fore.BLUE + "According to NordVPN, \
Least Busy " + Fore.GREEN + str(len(better_servers_list)) + Fore.BLUE +
              " Servers in \
" + Fore.GREEN + country_code.upper() + Fore.BLUE,
              end=" ")
        if area:
            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,
              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=" ")
        if anti_ddos:
            print(", anti_ddos =", anti_ddos, end=" ")
        if netflix:
            print(", netflix =", netflix, end=" ")

        print(Fore.BLUE + "Are: " + Fore.GREEN + str(better_servers_list) +
              Fore.BLUE + "\n")
    return better_servers_list
Beispiel #2
0
def display_servers(list_servers: List, port: str, area: str, p2p: bool, dedicated: bool, double_vpn: bool,
                    tor_over_vpn: bool, anti_ddos: bool, netflix: bool, location: float) -> None:
    servers_on_web = set()      # servers shown on the website

    # if list_servers was not a specific country it would be "all"
    json_res_list = api.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,
        netflix=netflix, location=location)
    # logger.debug(json_res_list)

    print(Style.BRIGHT + Fore.BLUE + "The NordVPN Servers In", Fore.GREEN +
          list_servers.upper() + Fore.BLUE, end=" ")
    if area:
        print("Area ", Fore.GREEN + area + Fore.BLUE, end=" ")
    if p2p:
        print("with " + Fore.GREEN + "p2p" + Fore.BLUE + " support", end=" ")
    if dedicated:
        print("with " + Fore.GREEN + "dedicated" + Fore.BLUE + " support", end=" ")
    if double_vpn:
        print("with " + Fore.GREEN + "double_vpn" + Fore.BLUE + " support", end=" ")
    if tor_over_vpn:
        print("with " + Fore.GREEN + "tor_over_vpn" + Fore.BLUE + " support", end=" ")
    if anti_ddos:
        print("with " + Fore.GREEN + "anti_ddos" + Fore.BLUE + " support", end=" ")
    if netflix:
        print("with " + Fore.GREEN + "netflix" + Fore.BLUE + " support", end=" ")
    print("Are:\n" + Style.RESET_ALL)

    # 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")
        servers_on_web.add(res["domain"][:res["domain"].find(".")])

    if not area:
        locations_in_country = locations.get_unique_locations(list_of_servers=json_res_list)
        print("The available Locations in country", list_servers.upper(), "are :")
        for eachLocation in locations_in_country:
            print(eachLocation[2])
        print("")

    if list_servers != "all" and not p2p and not dedicated and not double_vpn \
            and not tor_over_vpn and not anti_ddos and not netflix and not area:
            # else not applicable.
        print_latest_servers(list_servers=list_servers, port=port, server_set=servers_on_web)